aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/routes.go
blob: 6d0e529973b6e44938b3de4d15a95689758bf2ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)
	})
}