This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
JISQueueing/server/server.go

36 lines
1003 B
Go

package server
import (
"JISQueueing/server/socket"
"net/http"
"github.com/gorilla/mux"
)
//NewServerMux creates a new http handler object handling API requests
func NewServerMux() 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))
2020-01-31 03:03:02 +07:00
router.PathPrefix("/static").Handler(http.FileServer(http.Dir("./static")))
router.PathPrefix("/").HandlerFunc(indexHandler)
socket.StartRedisServer()
return router
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/index.html")
}