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

38 lines
1.1 KiB
Go

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