diff --git a/web/main.go b/web/main.go index af03743..1d26846 100644 --- a/web/main.go +++ b/web/main.go @@ -10,6 +10,8 @@ maintains a list of modules. When it runs, it executes all of its modules. package web import ( + "net/http" + "github.com/gin-gonic/gin" "go.uber.org/zap" @@ -27,7 +29,9 @@ type Service struct { // config Listen string `toml:"listen"` AccessLog bool `toml:"access_log"` + WebrootIndexDisable bool `toml:"webroot_index_disable"` Webroot string `toml:"webroot"` + WebrootFS http.FileSystem `toml:"-"` ACME struct { Enable bool `toml:"enable"` Domains []string `toml:"domains"` diff --git a/web/module.go b/web/module.go index b8d05de..23f2ff2 100644 --- a/web/module.go +++ b/web/module.go @@ -21,5 +21,17 @@ func (ws *Service) Bind(r *gin.Engine) { } ws.log.Info("bind modules", zap.Int("count", len(ws.modules))) - r.Use(static.Serve("/", static.LocalFile(ws.Webroot, false))) + if ws.Webroot != "" { + ws.WebrootFS = static.LocalFile(ws.Webroot, false) + } + r.Use(func(c *gin.Context) { + if !ws.WebrootIndexDisable { + _, err := ws.WebrootFS.Open(c.Request.URL.Path) + if err != nil { + c.FileFromFS("/", ws.WebrootFS) + return + } + } + c.FileFromFS(c.Request.URL.Path, ws.WebrootFS) + }) }