chore: serve static files from dir on dev

This commit is contained in:
juancwu 2026-04-11 14:34:50 +00:00
commit f25244b016
2 changed files with 11 additions and 2 deletions

View file

@ -33,9 +33,15 @@ func SetupRoutes(a *app.App) http.Handler {
)
// Static assets (bypass router groups — registered directly on mux)
var assetsFS http.FileSystem
if a.Cfg.IsProduction() {
sub, _ := fs.Sub(assets.AssetsFS, ".")
assetsFS = http.FS(sub)
} else {
assetsFS = http.Dir("./assets")
}
r.Mux().Handle("GET /assets/",
middleware.CacheStatic(http.StripPrefix("/assets/", http.FileServer(http.FS(sub)))),
middleware.CacheStatic(http.StripPrefix("/assets/", http.FileServer(assetsFS))),
)
// Public pages

View file

@ -220,6 +220,9 @@ func TestSetupRoutes_NotFound(t *testing.T) {
func TestSetupRoutes_StaticAssets(t *testing.T) {
testutil.ForEachDB(t, func(t *testing.T, dbi testutil.DBInfo) {
a := newTestApp(dbi)
// Force the embedded-FS branch so the test is independent of CWD;
// in dev we serve from ./assets on disk (see SetupRoutes).
a.Cfg.AppEnv = "production"
handler := SetupRoutes(a)
req := httptest.NewRequest(http.MethodGet, "/assets/css/output.css", nil)