From 5791786a9fd38a073e3e545e6be266b12c6dbb52 Mon Sep 17 00:00:00 2001 From: Abdulhade Date: Fri, 14 Nov 2025 03:46:57 +0300 Subject: [PATCH] Created api router --- api/http_handler.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/api/http_handler.go b/api/http_handler.go index 8ea5676..6834ea9 100644 --- a/api/http_handler.go +++ b/api/http_handler.go @@ -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)