99 "log"
1010 "net"
1111 "net/http"
12+ "os"
1213 "os/exec"
1314 pathpkg "path"
1415 "path/filepath"
@@ -19,10 +20,11 @@ import (
1920)
2021
2122type Serve struct {
22- Addr string
23- Root string
24- Info * log.Logger
25- Debug * log.Logger
23+ Addr string
24+ Root string
25+ RootFS * os.Root
26+ Info * log.Logger
27+ Debug * log.Logger
2628}
2729
2830func (s * Serve ) Start () error {
@@ -69,7 +71,7 @@ func (s *Serve) handler() http.Handler {
6971
7072 mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
7173 w .Header ().Set ("Content-Type" , "text/html; charset=utf-8" )
72- err := indexHTML .Execute (w , map [string ]interface {} {
74+ err := indexHTML .Execute (w , map [string ]any {
7375 "Explain" : explainAddr (s .Addr ),
7476 "Links" : []string {
7577 "/v1/list-repos" ,
@@ -100,7 +102,8 @@ func (s *Serve) handler() http.Handler {
100102 _ = enc .Encode (& resp )
101103 })
102104
103- fs := http .FileServer (http .Dir (s .Root ))
105+ safeFS := http .FS (s .RootFS .FS ())
106+ fs := http .FileServer (safeFS )
104107 svc := & Handler {
105108 Dir : func (_ context.Context , name string ) (string , error ) {
106109 return filepath .Join (s .Root , filepath .FromSlash (name )), nil
@@ -117,6 +120,7 @@ func (s *Serve) handler() http.Handler {
117120 }
118121 }
119122 },
123+ RootFS : s .RootFS ,
120124 }
121125 mux .Handle ("/repos/" , http .StripPrefix ("/repos/" , http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
122126 // Use git service if git is trying to clone. Otherwise show http.FileServer for convenience
0 commit comments