1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-10 09:52:51 +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

View File

@@ -1,14 +1,25 @@
package route
import (
"github.com/julienschmidt/httprouter"
"log"
"net/http"
"../controller"
"../controller/api"
"github.com/julienschmidt/httprouter"
"github.com/mgerb/mywebsite/server/controller"
"github.com/mgerb/mywebsite/server/controller/api"
)
func NonTLSRoutes() *httprouter.Router {
r := httprouter.New()
r.GET("/api/storedata", api.HandleSensorRequest)
// redirect to tls on not found
r.NotFound = http.HandlerFunc(tlsRedirect)
return r
}
func Routes() *httprouter.Router {
log.Println("Server Started")
@@ -53,3 +64,14 @@ func fileHandler(path string) http.HandlerFunc {
}
}
// redirect to tls
func tlsRedirect(w http.ResponseWriter, req *http.Request) {
// remove/add not default ports from req.Host
target := "https://" + req.Host + req.URL.Path
if len(req.URL.RawQuery) > 0 {
target += "?" + req.URL.RawQuery
}
http.Redirect(w, req, target, http.StatusTemporaryRedirect)
}