summary refs log tree commit diff stats
path: root/svc
diff options
context:
space:
mode:
Diffstat (limited to 'svc')
-rw-r--r--svc/conf.go10
-rw-r--r--svc/handlers.go2
-rw-r--r--svc/init.go7
-rw-r--r--svc/svc.go19
4 files changed, 28 insertions, 10 deletions
diff --git a/svc/conf.go b/svc/conf.go
index 90cac6a..f15bd13 100644
--- a/svc/conf.go
+++ b/svc/conf.go
@@ -15,6 +15,7 @@ import (
 // this struct.
 type Configuration struct {
 	Mu            sync.RWMutex
+	IsProxied     bool          `yaml:"BehindProxy"`
 	Port          int           `yaml:"ListenPort"`
 	LogFile       string        `yaml:"LogFile"`
 	DBType        string        `yaml:"DatabaseType"`
@@ -132,6 +133,7 @@ func parseConfigFlag() {
 func bindConfig() {
 	confObj.Mu.Lock()
 
+	confObj.IsProxied = viper.GetBool("BehindProxy")
 	confObj.Port = viper.GetInt("ListenPort")
 	confObj.LogFile = viper.GetString("LogFile")
 	confObj.DBType = strings.ToLower(viper.GetString("DatabaseType"))
@@ -157,7 +159,15 @@ func bindConfig() {
 	if *flagAssets != "" {
 		confObj.AssetsDir = *flagAssets
 	}
+	if *flagProxied {
+		confObj.IsProxied = true
+	}
 
+	if confObj.IsProxied {
+		log.Printf("Behind reverse proxy, not using host matching\n")
+	} else {
+		log.Printf("Matching host: %v\n", confObj.Instance.URL)
+	}
 	if confObj.StdoutLogging {
 		log.Printf("Logging to: stdout\n")
 	} else {
diff --git a/svc/handlers.go b/svc/handlers.go
index d3b8d8a..73ef869 100644
--- a/svc/handlers.go
+++ b/svc/handlers.go
@@ -21,7 +21,7 @@ func sendStaticEtag(w http.ResponseWriter, isCSS bool) {
 	if isCSS {
 		etag := getEtag(staticCache.cssMod)
 		w.Header().Set("ETag", "\""+etag+"\"")
-		w.Header().Set("Content-Time", txtutf8)
+		w.Header().Set("Content-Time", cssutf8)
 		return
 	}
 	etag := getEtag(staticCache.indexMod)
diff --git a/svc/init.go b/svc/init.go
index d7419de..082cef8 100644
--- a/svc/init.go
+++ b/svc/init.go
@@ -19,9 +19,10 @@ var (
 	flagHelp     *bool   = pflag.BoolP("help", "h", false, "Display the quick-help screen.")
 	flagMan      *bool   = pflag.BoolP("manual", "m", false, "Display the configuration manual.")
 	flagConfFile *string = pflag.StringP("config", "c", "", "The name/path of the configuration file you wish to use.")
-	flagAssets   *string = pflag.StringP("assets", "a", "", "The location of the getwtxt assets directory")
-	flagDBPath   *string = pflag.StringP("db", "d", "", "Path to the getwtxt database")
-	flagDBType   *string = pflag.StringP("dbtype", "t", "", "Type of database being used")
+	flagAssets   *string = pflag.StringP("assets", "a", "", "The location of the getwtxt assets directory.")
+	flagDBPath   *string = pflag.StringP("db", "d", "", "Path to the getwtxt database.")
+	flagDBType   *string = pflag.StringP("dbtype", "t", "", "Type of database being used.")
+	flagProxied  *bool   = pflag.BoolP("proxied", "p", false, "Use if getwtxt is behind a reverse proxy.")
 )
 
 // Holds the global configuration
diff --git a/svc/svc.go b/svc/svc.go
index 6284239..e5802d2 100644
--- a/svc/svc.go
+++ b/svc/svc.go
@@ -12,28 +12,35 @@ import (
 
 // Start is the initialization function for getwtxt
 func Start() {
+	before := time.Now()
 	initSvc()
 
 	// StrictSlash(true) allows /api and /api/
 	// to serve the same content without duplicating
 	// handlers/paths
 	index := mux.NewRouter().StrictSlash(true)
-	api := index.PathPrefix("/api").Subrouter()
-
-	setIndexRouting(index)
-	setEndpointRouting(api)
 
 	confObj.Mu.RLock()
 	portnum := fmt.Sprintf(":%v", confObj.Port)
+	if !confObj.IsProxied {
+		index.Host(confObj.Instance.URL)
+	}
 	confObj.Mu.RUnlock()
 
-	server := newServer(portnum, index)
+	setIndexRouting(index)
+	api := index.PathPrefix("/api").Subrouter()
+	setEndpointRouting(api)
 
+	server := newServer(portnum, index)
 	log.Printf("*** Listening on %v\n", portnum)
-	log.Printf("*** getwtxt %v Started :: %v ::\n\n", Vers, time.Now().Format(time.RFC3339))
+	log.Printf("*** getwtxt %v Startup finished at %v, took %v\n\n", Vers, time.Now().Format(time.RFC3339), time.Since(before))
 	errLog("", server.ListenAndServe())
 
 	closeLog <- true
+	killTickers()
+	killDB()
+	close(dbChan)
+	close(closeLog)
 }
 
 func newServer(port string, index *mux.Router) *http.Server {