1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-10 09:52:51 +00:00

server set up with app engine

This commit is contained in:
2016-08-22 00:01:53 -05:00
parent 6dac5aeb06
commit 34b463cd44
18 changed files with 827 additions and 33 deletions

54
server/route/route.go Normal file
View File

@@ -0,0 +1,54 @@
package route
import (
"github.com/julienschmidt/httprouter"
"log"
"net/http"
"mywebsite/server/controller"
"mywebsite/server/controller/api"
)
func Routes() *httprouter.Router {
log.Println("Server Started")
r := httprouter.New()
r.GET("/api/storedata", api.HandleSensorRequest)
r.GET("/api/allsensors", api.HandleAllSensors)
r.GET("/api/sensor/:location", api.HandleSensorByLocation)
r.GET("/api/sensor/:location/:year", api.HandleSensorByLocationYear)
r.GET("/api/sensor/:location/:year/:monthname", api.HandleSensorByLocationMonth)
r.GET("/discord", controller.DiscordRedirect)
r.GET("/vpn", controller.VPNRedirect)
r.GET("/camera", controller.CameraRedirect)
//set up public folder path
r.ServeFiles("/public/*filepath", http.Dir("./public/"))
//route every invalid request to template file
//routing is all handled on the client side with angular
r.NotFound = http.HandlerFunc(fileHandler("./public/index.html"))
return r
}
//route requests to static files
func routerFileHandler(path string) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
http.ServeFile(w, r, path)
}
}
//function to serve files with standard net/http library
func fileHandler(path string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, path)
}
}