diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2021-08-04 20:06:07 -0400 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2021-08-04 20:06:07 -0400 |
| commit | 742938b00222c7ad57ad11eb24850d9202c2503d (patch) | |
| tree | e0d1d033027d5dd553c213ed41bb8ae201d6a285 /cmd/web/routes.go | |
| parent | a5a49ff08056a67cc57435f219aa157342a0d9a0 (diff) | |
| download | steam-export-742938b00222c7ad57ad11eb24850d9202c2503d.tar.gz steam-export-742938b00222c7ad57ad11eb24850d9202c2503d.tar.xz | |
Pretty large structural changes. Non-building development snapshot
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) + }) +} |
