/
router.go
47 lines (38 loc) · 1.42 KB
/
router.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
package main
import (
"io/fs"
"net/http"
"github.com/gorilla/mux"
"github.com/interpose/middleware"
"github.com/justinas/alice"
)
func router(config *Global) (http.Handler, error) {
router := mux.NewRouter()
POST := router.Methods("POST").Subrouter()
GET := router.Methods("GET", "HEAD").Subrouter()
h := handler{Global: config, router: router}
GET.HandleFunc("/", h.Index).Name("index")
GET.HandleFunc("/goroutines", h.Goroutines)
GET.HandleFunc("/{template:(?:about|privacy|TOS|DMCA)}", h.TemplateOnly)
GET.HandleFunc("/traceoverlay/{manifest_index}", h.TraceOverlay).Name("traceoverlay")
GET.HandleFunc("/traceoverlay/cine/{zip}/{series}", h.TraceOverlayCINE).Name("traceoverlay_cine")
GET.HandleFunc("/traceoverlay/cinehtml/{zip}/{series}", h.TraceOverlayCINEHTML).Name("traceoverlay_cinehtml")
GET.HandleFunc("/listproject", h.ListProject).Name("listproject")
//
// POST
//
POST.Handle("/", http.NotFoundHandler())
POST.HandleFunc("/traceoverlay/{manifest_index}", h.TraceOverlayPost)
// Static assets
assetFilesystem, err := fs.Sub(embeddedTemplates, "templates/static")
if err != nil {
return nil, err
}
staticHandler := http.StripPrefix(h.Assets(), http.FileServer(http.FS(assetFilesystem)))
GET.PathPrefix(h.Assets()).Handler(middleware.MaxAgeHandler(60*60*24*364, staticHandler))
standard := alice.New(
// Log all requests to STDOUT
middleware.GorillaLog(),
)
return standard.Then(router), nil
}