this repo has no description
1package routes
2
3import (
4 "net/http"
5
6 "github.com/go-chi/chi/v5"
7 "github.com/icyphox/bild/legit/config"
8)
9
10// Checks for gitprotocol-http(5) specific smells; if found, passes
11// the request on to the git http service, else render the web frontend.
12func (d *deps) Multiplex(w http.ResponseWriter, r *http.Request) {
13 path := chi.URLParam(r, "*")
14
15 if r.URL.RawQuery == "service=git-receive-pack" {
16 w.WriteHeader(http.StatusBadRequest)
17 w.Write([]byte("no pushing allowed!"))
18 return
19 }
20
21 if path == "info/refs" &&
22 r.URL.RawQuery == "service=git-upload-pack" &&
23 r.Method == "GET" {
24 d.InfoRefs(w, r)
25 } else if path == "git-upload-pack" && r.Method == "POST" {
26 d.UploadPack(w, r)
27 } else if r.Method == "GET" {
28 d.RepoIndex(w, r)
29 }
30}
31
32func Handlers(c *config.Config) http.Handler {
33 r := chi.NewRouter()
34 d := deps{c}
35
36 r.Get("/static/{file}", d.ServeStatic)
37
38 r.Route("/@{user}", func(r chi.Router) {
39 r.Get("/", d.Index)
40 r.Route("/{name}", func(r chi.Router) {
41 r.Get("/", d.Multiplex)
42 r.Post("/", d.Multiplex)
43
44 r.Route("/tree/{ref}", func(r chi.Router) {
45 r.Get("/*", d.RepoTree)
46 })
47
48 r.Route("/blob/{ref}", func(r chi.Router) {
49 r.Get("/*", d.FileContent)
50 })
51
52 r.Get("/log/{ref}", d.Log)
53 r.Get("/archive/{file}", d.Archive)
54 r.Get("/commit/{ref}", d.Diff)
55 r.Get("/refs/", d.Refs)
56
57 // Catch-all routes
58 r.Get("/*", d.Multiplex)
59 r.Post("/*", d.Multiplex)
60 })
61 })
62
63 return r
64}