diff options
Diffstat (limited to 'cmd/web/routes.go')
| -rw-r--r-- | cmd/web/routes.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/cmd/web/routes.go b/cmd/web/routes.go new file mode 100644 index 0000000..6d0e529 --- /dev/null +++ b/cmd/web/routes.go @@ -0,0 +1,40 @@ +package main + +import ( + "net/http" + + "github.com/gorilla/mux" +) + +func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) { + rtr := mux.NewRouter() + + rtr.PathPrefix("/api/v1").Handler(a.HandleAPIv1()) + + rtr.Handle("/quit", UnauthorizedIfNotLocal(http.HandlerFunc(HandleQuit))) + rtr.Handle("/setLib", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLib))) + rtr.Handle("/delete", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleDelete))) + rtr.Handle("/install", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleInstall))) + rtr.Handle("/status", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleStats))) + + rtr.HandleFunc("/steam-export-web.exe", ServeSelf) + rtr.HandleFunc("/download/{game}", a.HandleDownload) + rtr.PathPrefix("/static").Handler( + http.FileServer(http.FS(embeddedStatic))) + rtr.HandleFunc("/", a.HandleIndex) + + rtr.ServeHTTP(w, r) +} + +func (a *App) HandleAPIv1() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + rtr := mux.NewRouter() + + rtr.Handle("/quit", UnauthorizedIfNotLocal(http.HandlerFunc(HandleQuit))) + rtr.Handle("/library", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLib))) + rtr.Handle("/library/delete", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLib))) + rtr.Handle("/library/delete", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLib))) + + rtr.ServeHTTP(w, r) + }) +} |
