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 19:07:38 -0400
committerGitHub <noreply@github.com>2019-06-11 19:07:38 -0400
commit9a0bbd716ff234475dc7b2efa3e3c2ef96bd5454 (patch)
tree7915b74fe7be9bde61ccfd408cc3bbeb170265d8 /svc/svc.go
parentd4af885c40ba55ea0ed9adade98afe0658099c47 (diff)
parent45ee3c060433c58a0a89de223655381933e7df11 (diff)
downloadgetwtxt-9a0bbd716ff234475dc7b2efa3e3c2ef96bd5454.tar.gz
Merge pull request #4 from getwtxt/tls-conn-and-name-resolv
TLS Support, Name Resolution Support
Diffstat (limited to 'svc/svc.go')
-rw-r--r--svc/svc.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/svc/svc.go b/svc/svc.go
index 6284239..1748bf0 100644
--- a/svc/svc.go
+++ b/svc/svc.go
@@ -12,28 +12,42 @@ 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)
+	}
+	TLS := confObj.TLS.Use
+	TLSCert := confObj.TLS.Cert
+	TLSKey := confObj.TLS.Key
 	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))
-	errLog("", server.ListenAndServe())
+	log.Printf("*** getwtxt %v Startup finished at %v, took %v\n\n", Vers, time.Now().Format(time.RFC3339), time.Since(before))
+	if TLS {
+		errLog("", server.ListenAndServeTLS(TLSCert, TLSKey))
+	} else {
+		errLog("", server.ListenAndServe())
+	}
 
 	closeLog <- true
+	killTickers()
+	killDB()
+	close(dbChan)
+	close(closeLog)
 }
 
 func newServer(port string, index *mux.Router) *http.Server {