diff options
Diffstat (limited to 'internal/web/assets.go')
-rw-r--r-- | internal/web/assets.go | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/internal/web/assets.go b/internal/web/assets.go index aab4346eb..470bab752 100644 --- a/internal/web/assets.go +++ b/internal/web/assets.go @@ -22,11 +22,9 @@ import ( "fmt" "net/http" "path" - "path/filepath" "strings" "github.com/gin-gonic/gin" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/log" ) @@ -53,22 +51,6 @@ func (fs fileSystem) Open(path string) (http.File, error) { return f, nil } -func (m *Module) mountAssetsFilesystem(group *gin.RouterGroup) { - webAssetsAbsFilePath, err := filepath.Abs(config.GetWebAssetBaseDir()) - if err != nil { - log.Panicf("mountAssetsFilesystem: error getting absolute path of assets dir: %s", err) - } - - fs := fileSystem{http.Dir(webAssetsAbsFilePath)} - - // use the cache middleware on all handlers in this group - group.Use(m.assetsCacheControlMiddleware(fs)) - - // serve static file system in the root of this group, - // will end up being something like "/assets/" - group.StaticFS("/", fs) -} - // getAssetFileInfo tries to fetch the ETag for the given filePath from the module's // assetsETagCache. If it can't be found there, it uses the provided http.FileSystem // to generate a new ETag to go in the cache, which it then returns. @@ -115,6 +97,9 @@ func (m *Module) getAssetETag(filePath string, fs http.FileSystem) (string, erro // // See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match // and: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control +// +// todo: move this middleware out of the 'web' package and into the 'middleware' +// package along with the other middlewares func (m *Module) assetsCacheControlMiddleware(fs http.FileSystem) gin.HandlerFunc { return func(c *gin.Context) { // set this Cache-Control header to instruct clients to validate the response with us |