Created api router
This commit is contained in:
@@ -14,10 +14,30 @@ func ping(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func serveStaticFile(fileName string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO: check out why does this even need the request? does it take the file path from it,
|
||||
// is is possible to manipulate the path like using .. to get around?!
|
||||
http.ServeFile(w, r, "front_files/"+fileName)
|
||||
}
|
||||
}
|
||||
|
||||
func createSession(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `
|
||||
{
|
||||
"sessionId":"XyZ123"
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
func signalWS(w http.ResponseWriter, r *http.Request) {
|
||||
// This will create the websocket for the signaling service.
|
||||
vars := mux.Vars(r)
|
||||
party := vars["party"]
|
||||
session := vars["session"]
|
||||
|
||||
fmt.Printf("Initiating a websocket, party=%s session=%s", party, session)
|
||||
|
||||
}
|
||||
|
||||
func BuildRouter(listenAddress string) {
|
||||
mainRouter := mux.NewRouter()
|
||||
|
||||
@@ -26,7 +46,9 @@ func BuildRouter(listenAddress string) {
|
||||
mainRouter.HandleFunc("/index.js", serveStaticFile("index.js"))
|
||||
mainRouter.HandleFunc("/index.css", serveStaticFile("index.css"))
|
||||
|
||||
// api_router := base_router.PathPrefix("/api").Subrouter()
|
||||
api_router := mainRouter.PathPrefix("/api").Subrouter()
|
||||
api_router.HandleFunc("/session", createSession).Methods("POST")
|
||||
api_router.HandleFunc("/signal/session/{session}/party/{party}", signalWS)
|
||||
|
||||
err := http.ListenAndServe(listenAddress, mainRouter)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user