1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: serve static assets without compression in dev mode

This commit is contained in:
Ferdinand Mütsch 2023-01-07 23:59:50 +01:00
parent 0cb1afc5b5
commit 0c51d8682b

14
main.go
View File

@ -2,6 +2,7 @@ package main
import ( import (
"embed" "embed"
"github.com/lpar/gzipped/v2"
"io/fs" "io/fs"
"log" "log"
"net" "net"
@ -15,7 +16,6 @@ import (
"github.com/emvi/logbuch" "github.com/emvi/logbuch"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/lpar/gzipped/v2"
httpSwagger "github.com/swaggo/http-swagger" httpSwagger "github.com/swaggo/http-swagger"
conf "github.com/muety/wakapi/config" conf "github.com/muety/wakapi/config"
@ -279,12 +279,12 @@ func main() {
embeddedStatic, _ := fs.Sub(staticFiles, "static") embeddedStatic, _ := fs.Sub(staticFiles, "static")
static := conf.ChooseFS("static", embeddedStatic) static := conf.ChooseFS("static", embeddedStatic)
assetsFileServer := gzipped.FileServer(fsutils.NewExistsHttpFS( assetsStaticFs := fsutils.NewExistsHttpFS(fsutils.NewExistsFS(static).WithCache(!config.IsDev()))
fsutils.NewExistsFS(static).WithCache(!config.IsDev()), assetsFileServer := http.FileServer(assetsStaticFs)
)) if !config.IsDev() {
staticFileServer := http.FileServer(http.FS( assetsFileServer = gzipped.FileServer(assetsStaticFs)
fsutils.NeuteredFileSystem{FS: static}, }
)) staticFileServer := http.FileServer(http.FS(fsutils.NeuteredFileSystem{FS: static}))
router.PathPrefix("/contribute.json").Handler(staticFileServer) router.PathPrefix("/contribute.json").Handler(staticFileServer)
router.PathPrefix("/assets").Handler(assetsFileServer) router.PathPrefix("/assets").Handler(assetsFileServer)