this repo has no description
1package knotserver 2 3import ( 4 "fmt" 5 "net/http" 6 7 "github.com/go-chi/chi/v5" 8 "github.com/icyphox/bild/knotserver/config" 9 "github.com/icyphox/bild/knotserver/db" 10) 11 12func Setup(c *config.Config, db *db.DB) (http.Handler, error) { 13 r := chi.NewRouter() 14 15 h := Handle{ 16 c: c, 17 db: db, 18 } 19 20 r.Route("/settings", func(r chi.Router) { 21 r.Get("/keys", h.Keys) 22 r.Put("/keys", h.Keys) 23 }) 24 25 r.Get("/", h.Index) 26 r.Route("/{did}", func(r chi.Router) { 27 // Repo routes 28 r.Route("/{name}", func(r chi.Router) { 29 r.Get("/", h.RepoIndex) 30 r.Get("/info/refs", h.InfoRefs) 31 r.Post("/git-upload-pack", h.UploadPack) 32 33 r.Route("/tree/{ref}", func(r chi.Router) { 34 r.Get("/*", h.RepoTree) 35 }) 36 37 r.Route("/blob/{ref}", func(r chi.Router) { 38 r.Get("/*", h.FileContent) 39 }) 40 41 r.Get("/log/{ref}", h.Log) 42 r.Get("/archive/{file}", h.Archive) 43 r.Get("/commit/{ref}", h.Diff) 44 r.Get("/refs/", h.Refs) 45 }) 46 }) 47 48 r.Route("/repo", func(r chi.Router) { 49 r.Put("/new", h.NewRepo) 50 }) 51 52 r.Route("/internal", func(r chi.Router) { 53 r.Use(h.VerifySignature) 54 r.Get("/health", h.Health) 55 }) 56 57 return r, nil 58} 59 60type Handle struct { 61 c *config.Config 62 db *db.DB 63} 64 65func (h *Handle) Multiplex(w http.ResponseWriter, r *http.Request) { 66 path := chi.URLParam(r, "*") 67 68 if r.URL.RawQuery == "service=git-receive-pack" { 69 w.WriteHeader(http.StatusBadRequest) 70 w.Write([]byte("no pushing allowed!")) 71 return 72 } 73 74 fmt.Println(r.URL.RawQuery) 75 fmt.Println(r.Method) 76 77 if path == "info/refs" && 78 r.URL.RawQuery == "service=git-upload-pack" && 79 r.Method == "GET" { 80 h.InfoRefs(w, r) 81 } else if path == "git-upload-pack" && r.Method == "POST" { 82 h.UploadPack(w, r) 83 } else if r.Method == "GET" { 84 h.RepoIndex(w, r) 85 } 86}