@@ -2,6 +2,7 @@ package api
22
33import (
44 "context"
5+ "fmt"
56 "net/http"
67 "net/http/cgi"
78 "os"
@@ -15,7 +16,6 @@ import (
1516 "github.com/go-chi/hostrouter"
1617 "github.com/pomdtr/smallweb/internal/app"
1718 "github.com/pomdtr/smallweb/internal/utils"
18- "golang.org/x/net/webdav"
1919)
2020
2121type GetBlobsOutput struct {
@@ -44,7 +44,6 @@ func NewHandler(conf *utils.Config) http.Handler {
4444 r := chi .NewRouter ()
4545 hr := hostrouter .New ()
4646
47- hr .Map ("webdav.localhost" , webdavRouter (conf ))
4847 hr .Map ("api.localhost" , apiRouter (conf ))
4948 hr .Map ("git.localhost" , gitRouter (conf ))
5049 hr .Map ("*" , catchAllRouter ())
@@ -54,17 +53,6 @@ func NewHandler(conf *utils.Config) http.Handler {
5453 return r
5554}
5655
57- func webdavRouter (conf * utils.Config ) chi.Router {
58- r := chi .NewRouter ()
59-
60- r .Handle ("/*" , & webdav.Handler {
61- FileSystem : webdav .Dir (conf .String ("dir" )),
62- LockSystem : webdav .NewMemLS (),
63- })
64-
65- return r
66- }
67-
6856func apiRouter (conf * utils.Config ) chi.Router {
6957 r := chi .NewRouter ()
7058
@@ -152,7 +140,13 @@ func gitRouter(conf *utils.Config) chi.Router {
152140 },
153141 }
154142
155- r .HandleFunc ("/*" , func (w http.ResponseWriter , r * http.Request ) {
143+ r .HandleFunc ("/{app}/*" , func (w http.ResponseWriter , r * http.Request ) {
144+ appname := chi .URLParam (r , "app" )
145+ if conf .String (fmt .Sprintf ("apps.%s.privacy" , appname )) != "public" {
146+ http .Error (w , "Not found" , http .StatusNotFound )
147+ return
148+ }
149+
156150 if strings .HasSuffix (r .URL .Path , "/git-receive-pack" ) {
157151 http .Error (w , "pushes are disabled" , http .StatusForbidden )
158152 return
0 commit comments