diff --git a/conf/wide.go b/conf/wide.go index 4279996..7f6c679 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -249,7 +249,7 @@ func Save() bool { } // Load loads the configurations from wide.json. -func Load(confPath, confIP, confPort, confServer, confContext, confChannel string, confDocker bool) { +func Load(confPath, confIP, confPort, confServer, confStaticServer, confContext, confChannel string, confDocker bool) { bytes, _ := ioutil.ReadFile(confPath) err := json.Unmarshal(bytes, &Wide) @@ -262,8 +262,7 @@ func Load(confPath, confIP, confPort, confServer, confContext, confChannel strin // keep the raw content json.Unmarshal(bytes, &rawWide) - // upgrade if need - upgrade() + glog.V(5).Info("Conf: \n" + string(bytes)) // Working Driectory Wide.WD = util.OS.Pwd() @@ -299,13 +298,17 @@ func Load(confPath, confIP, confPort, confServer, confContext, confChannel strin Wide.Server = confServer } + // Static Server + Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", Wide.IP, 1) + if "" != confStaticServer { + Wide.StaticServer = confStaticServer + } + // Context if "" != confContext { Wide.Context = confContext } - // Static Server - Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", Wide.IP, 1) Wide.StaticResourceVersion = strings.Replace(Wide.StaticResourceVersion, "${time}", strconv.FormatInt(time.Now().UnixNano(), 10), 1) // Channel @@ -318,7 +321,8 @@ func Load(confPath, confIP, confPort, confServer, confContext, confChannel strin Wide.Server = strings.Replace(Wide.Server, "{Port}", Wide.Port, 1) Wide.StaticServer = strings.Replace(Wide.StaticServer, "{Port}", Wide.Port, 1) - glog.V(5).Info("Conf: \n" + string(bytes)) + // upgrade if need + upgrade() initWorkspaceDirs() initCustomizedConfs() diff --git a/main.go b/main.go index e7d6299..b264ff8 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,7 @@ func init() { confIP := flag.String("ip", "", "ip to visit") confPort := flag.String("port", "", "port to visit") confServer := flag.String("server", "", "this will overwrite Wide.Server if specified") + confStaticServer := flag.String("static_server", "", "this will overwrite Wide.StaticServer if specified") confContext := flag.String("context", "", "this will overwrite Wide.Context if specified") confChannel := flag.String("channel", "", "this will overwrite Wide.XXXChannel if specified") confStat := flag.Bool("stat", false, "whether report statistics periodically") @@ -69,7 +70,7 @@ func init() { event.Load() - conf.Load(*confPath, *confIP, *confPort, *confServer, *confContext, *confChannel, *confDocker) + conf.Load(*confPath, *confIP, *confPort, *confServer, *confStaticServer, *confContext, *confChannel, *confDocker) conf.FixedTimeCheckEnv() conf.FixedTimeSave() @@ -91,6 +92,9 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { } httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge + if "" != conf.Wide.Context { + httpSession.Options.Path = conf.Wide.Context + } httpSession.Save(r, w) // create a Wide session @@ -148,6 +152,9 @@ func startHandler(w http.ResponseWriter, r *http.Request) { } httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge + if "" != conf.Wide.Context { + httpSession.Options.Path = conf.Wide.Context + } httpSession.Save(r, w) username := httpSession.Values["username"].(string) @@ -185,6 +192,9 @@ func keyboardShortcutsHandler(w http.ResponseWriter, r *http.Request) { } httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge + if "" != conf.Wide.Context { + httpSession.Options.Path = conf.Wide.Context + } httpSession.Save(r, w) username := httpSession.Values["username"].(string) @@ -214,6 +224,9 @@ func aboutHandler(w http.ResponseWriter, r *http.Request) { } httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge + if "" != conf.Wide.Context { + httpSession.Options.Path = conf.Wide.Context + } httpSession.Save(r, w) username := httpSession.Values["username"].(string) diff --git a/session/users.go b/session/users.go index ecee3bf..70c6d9f 100644 --- a/session/users.go +++ b/session/users.go @@ -54,6 +54,9 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) { } httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge + if "" != conf.Wide.Context { + httpSession.Options.Path = conf.Wide.Context + } httpSession.Save(r, w) username := httpSession.Values["username"].(string) @@ -186,6 +189,9 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) { httpSession.Values["username"] = args.Username httpSession.Values["id"] = strconv.Itoa(rand.Int()) httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge + if "" != conf.Wide.Context { + httpSession.Options.Path = conf.Wide.Context + } httpSession.Save(r, w) glog.Infof("Created a HTTP session [%s] for user [%s]", httpSession.Values["id"].(string), args.Username) diff --git a/shell/shells.go b/shell/shells.go index 1d7849c..8042a30 100644 --- a/shell/shells.go +++ b/shell/shells.go @@ -49,6 +49,9 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { } httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge + if "" != conf.Wide.Context { + httpSession.Options.Path = conf.Wide.Context + } httpSession.Save(r, w) // create a wide session