package server import ( "JISQueueing/server/socket" "net/http" "github.com/gorilla/mux" ) //NewServerMux creates a new http handler object handling API requests func NewServerMux(debug bool) http.Handler { router := mux.NewRouter() router.NotFoundHandler = http.HandlerFunc(NotFound) postRouter := router.Methods("POST").PathPrefix("/api").Subrouter() postRouter.HandleFunc("/login", Login) postRouter.HandleFunc("/logout", Logout) socketRouter := router.PathPrefix("/ws").Subrouter() socketRouter.HandleFunc("/display", socket.DisplaySocket) socketRouter.HandleFunc("/kiosk", socket.KioskSocket) socketRouter.HandleFunc("/staff", socket.StaffSocket) router.PathPrefix("/api").Handler(http.HandlerFunc(NotFound)) router.PathPrefix("/assets").Handler(http.FileServer(http.Dir("./static/"))) router.PathPrefix("/css").Handler(http.FileServer(http.Dir("./static/"))) //NotFound : A helper function that responds with a 404 status code and an error router.PathPrefix("/js").Handler(http.FileServer(http.Dir("./static/"))) router.PathPrefix("/").HandlerFunc(indexHandler) return router } func indexHandler(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./static/index.html") }