1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-11 10:22:53 +00:00
This commit is contained in:
2017-07-25 18:28:20 -05:00
parent 081334ee20
commit c66a8e3def
9 changed files with 106 additions and 62 deletions

46
main.go Normal file
View File

@@ -0,0 +1,46 @@
package main
import (
"log"
"net/http"
"golang.org/x/crypto/acme/autocert"
"github.com/NYTimes/gziphandler"
"github.com/mgerb/mywebsite/server/controller/api"
"github.com/mgerb/mywebsite/server/db"
"github.com/mgerb/mywebsite/server/route"
"github.com/mgerb/mywebsite/server/utils"
)
func main() {
configurations := utils.ReadConfig()
flags := utils.ParseFlags()
db.Configure(configurations.Database)
api.Configure(configurations.Api)
db.Mongo.Connect()
//register middleware
handle := gziphandler.GzipHandler(route.Routes())
if flags.TLS {
// start server on port 80 to redirect
go http.ListenAndServe(":80", route.NonTLSRoutes())
log.Println("Starting TLS server...")
// start TLS server
log.Fatal(http.Serve(autocert.NewListener(), handle))
} else {
log.Println("Starting basic server...")
// start basic server
http.ListenAndServe(configurations.Address, handle)
}
}