From 0c51d8682b31204cd8e8b27045c411df38ca8487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Sat, 7 Jan 2023 23:59:50 +0100 Subject: [PATCH] chore: serve static assets without compression in dev mode --- main.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index c4cf24c..428528c 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "embed" + "github.com/lpar/gzipped/v2" "io/fs" "log" "net" @@ -15,7 +16,6 @@ import ( "github.com/emvi/logbuch" "github.com/gorilla/handlers" "github.com/gorilla/mux" - "github.com/lpar/gzipped/v2" httpSwagger "github.com/swaggo/http-swagger" conf "github.com/muety/wakapi/config" @@ -279,12 +279,12 @@ func main() { embeddedStatic, _ := fs.Sub(staticFiles, "static") static := conf.ChooseFS("static", embeddedStatic) - assetsFileServer := gzipped.FileServer(fsutils.NewExistsHttpFS( - fsutils.NewExistsFS(static).WithCache(!config.IsDev()), - )) - staticFileServer := http.FileServer(http.FS( - fsutils.NeuteredFileSystem{FS: static}, - )) + assetsStaticFs := fsutils.NewExistsHttpFS(fsutils.NewExistsFS(static).WithCache(!config.IsDev())) + assetsFileServer := http.FileServer(assetsStaticFs) + if !config.IsDev() { + assetsFileServer = gzipped.FileServer(assetsStaticFs) + } + staticFileServer := http.FileServer(http.FS(fsutils.NeuteredFileSystem{FS: static})) router.PathPrefix("/contribute.json").Handler(staticFileServer) router.PathPrefix("/assets").Handler(assetsFileServer)