mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-10 09:52:51 +00:00
moved server to separate repo
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"server/controller"
|
||||
"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)
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user