summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorJesse Hallam <jesse.hallam@gmail.com>2018-06-14 11:26:22 -0400
committerChristopher Speller <crspeller@gmail.com>2018-06-14 08:26:22 -0700
commitf106417103b036e8c349531f25487e526252d084 (patch)
tree6fe30dce0d91d04a54779b2183450cf1a90d8b66 /cmd
parentd0cda0500eb4fa8818323a8680ac38a504aa9c15 (diff)
downloadchat-f106417103b036e8c349531f25487e526252d084.tar.gz
chat-f106417103b036e8c349531f25487e526252d084.tar.bz2
chat-f106417103b036e8c349531f25487e526252d084.zip
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.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mattermost/commands/config.go38
1 files changed, 36 insertions, 2 deletions
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
+}