-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler.go
55 lines (45 loc) · 1.35 KB
/
handler.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"context"
"net/http"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
handlers "github.com/tmthrgd/httphandlers"
"go.tmthrgd.dev/spork/web"
)
func handler(ctx context.Context) http.Handler {
router := chi.NewRouter()
router.Use(
handlers.AccessLogWrap(nil),
handlers.SecurityHeadersWrap(nil),
handlers.SetHeaderWrap("Server", "spork (audacious control panel)"),
)
router.NotFound(web.NotFoundHandler())
router.MethodNotAllowed(web.MethodNotAllowedHandler())
// assets routes
web.MountAssets(router)
// pprof handler
router.Mount("/debug", middleware.Profiler())
// HTML page routes
router.Group(func(r chi.Router) {
r.Use(middleware.NoCache)
r.Get("/", controlsHandler())
r.Get("/playlist", playlistHandler())
})
// API routes
router.Group(func(r chi.Router) {
r.Use(middleware.NoCache)
r.Get("/jump/{pos}", jumpHandler())
r.Get("/download/{pos}", downloadHandler())
r.Get("/controls/playpause", playPauseHandler())
r.Get("/controls/stop", stopHandler())
r.Get("/controls/prev", prevHandler())
r.Get("/controls/next", nextHandler())
r.Get("/controls/repeat", repeatHandler())
r.Get("/controls/shuffle", shuffleHandler())
r.Get("/controls/volume/{vol}", setVolumeHandler())
r.Get("/playlist/updates", playlistUpdateHandler(ctx))
r.Get("/launch", launchHandler())
})
return router
}