From f25244b0164650c401b7bb70ab84ca99d9fa5a3b Mon Sep 17 00:00:00 2001 From: juancwu Date: Sat, 11 Apr 2026 14:34:50 +0000 Subject: [PATCH] chore: serve static files from dir on dev --- internal/routes/routes.go | 10 ++++++++-- internal/routes/routes_test.go | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/routes/routes.go b/internal/routes/routes.go index 3105eee..f197256 100644 --- a/internal/routes/routes.go +++ b/internal/routes/routes.go @@ -33,9 +33,15 @@ func SetupRoutes(a *app.App) http.Handler { ) // Static assets (bypass router groups — registered directly on mux) - sub, _ := fs.Sub(assets.AssetsFS, ".") + 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 diff --git a/internal/routes/routes_test.go b/internal/routes/routes_test.go index 9be105e..e64e0e9 100644 --- a/internal/routes/routes_test.go +++ b/internal/routes/routes_test.go @@ -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)