mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-11 10:22:53 +00:00
add tls
This commit is contained in:
46
main.go
Normal file
46
main.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user