From f106417103b036e8c349531f25487e526252d084 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Thu, 14 Jun 2018 11:26:22 -0400 Subject: MM-10367: rewrite subpath assets on startup (#8944) Examine ServiceSettings.SiteURL on startup and rewrite assets accordingly if not in a development environment. Also export `mattermost config subpath` command to manually do same. This accompanies a webapp PR to use the updated `root.html` to define the necessary webpack asset path for dynamically loading assets. --- cmd/mattermost/commands/config.go | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/mattermost/commands/config.go b/cmd/mattermost/commands/config.go index 81ac765ec..0b0e00f35 100644 --- a/cmd/mattermost/commands/config.go +++ b/cmd/mattermost/commands/config.go @@ -5,12 +5,14 @@ package commands import ( "encoding/json" - "errors" "os" + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" - "github.com/spf13/cobra" + "github.com/mattermost/mattermost-server/web" ) var ConfigCmd = &cobra.Command{ @@ -25,9 +27,22 @@ var ValidateConfigCmd = &cobra.Command{ RunE: configValidateCmdF, } +var ConfigSubpathCmd = &cobra.Command{ + Use: "subpath", + Short: "Update client asset loading to use the configured subpath", + Long: "Update the hard-coded production client asset paths to take into account Mattermost running on a subpath.", + Example: ` config subpath + config subpath --path /mattermost + config subpath --path /`, + RunE: configSubpathCmdF, +} + func init() { + ConfigSubpathCmd.Flags().String("path", "", "Optional subpath; defaults to value in SiteURL") + ConfigCmd.AddCommand( ValidateConfigCmd, + ConfigSubpathCmd, ) RootCmd.AddCommand(ConfigCmd) } @@ -65,3 +80,22 @@ func configValidateCmdF(command *cobra.Command, args []string) error { CommandPrettyPrintln("The document is valid") return nil } + +func configSubpathCmdF(command *cobra.Command, args []string) error { + a, err := InitDBCommandContextCobra(command) + if err != nil { + return err + } + defer a.Shutdown() + + path, err := command.Flags().GetString("path") + if err != nil { + return errors.Wrap(err, "failed reading path") + } else if path == "" { + return web.UpdateAssetsSubpathFromConfig(a.Config()) + } else if err := web.UpdateAssetsSubpath(path); err != nil { + return errors.Wrap(err, "failed to update assets subpath") + } + + return nil +} -- cgit v1.2.3-1-g7c22