summary refs log tree commit diff stats
path: root/svc/svc.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-11 18:13:30 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-11 18:14:07 -0400
commit6dad1372a4680f2314a057b831f8cb2ef44dcf1b (patch)
treed95c10c760045c27714bc0b387f06ca8d2771eae /svc/svc.go
parentd4af885c40ba55ea0ed9adade98afe0658099c47 (diff)
downloadgetwtxt-6dad1372a4680f2314a057b831f8cb2ef44dcf1b.tar.gz
check if behind reverse proxy
Diffstat (limited to 'svc/svc.go')
-rw-r--r--svc/svc.go19
1 files changed, 13 insertions, 6 deletions
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 {