- Add assets package with dev/prod build tags - Dev: serve from filesystem with Cache-Control: no-store - Prod: use hashfs for cache-busting URLs - Add LiveClock component to show SSE connection status - Update templates to use StaticPath for asset URLs
23 lines
488 B
Go
23 lines
488 B
Go
//go:build dev
|
|
|
|
package assets
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func Handler() http.Handler {
|
|
log.Debug().Str("path", DirectoryPath).Msg("static assets served from filesystem")
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Cache-Control", "no-store")
|
|
http.StripPrefix("/assets/", http.FileServerFS(os.DirFS(DirectoryPath))).ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
func StaticPath(path string) string {
|
|
return "/assets/" + path
|
|
}
|