diff --git a/snippetbox/cmd/web/routes.go b/snippetbox/cmd/web/routes.go index 1553ad5..44b8e82 100644 --- a/snippetbox/cmd/web/routes.go +++ b/snippetbox/cmd/web/routes.go @@ -5,6 +5,8 @@ import ( "github.com/julienschmidt/httprouter" "github.com/justinas/alice" + + "snippetbox.chaosfem.tw/ui" ) // routes ... @@ -20,8 +22,8 @@ func (app *application) routes() http.Handler { }) // setup server for static files - fileServer := http.FileServer(http.Dir("./ui/static")) - router.Handler(http.MethodGet, "/static/*filepath", http.StripPrefix("/static", fileServer)) + fileServer := http.FileServer(http.FS(ui.Files)) + router.Handler(http.MethodGet, "/static/*filepath", fileServer) dynamic := alice.New(app.sessionManager.LoadAndSave, noSurf, app.authenticate) diff --git a/snippetbox/ui/efs.go b/snippetbox/ui/efs.go new file mode 100644 index 0000000..b4213ae --- /dev/null +++ b/snippetbox/ui/efs.go @@ -0,0 +1,8 @@ +package ui + +import ( + "embed" +) + +//go:embed "static" +var Files embed.FS