diff options
Diffstat (limited to 'server/main.go')
| -rw-r--r-- | server/main.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/server/main.go b/server/main.go index 011f286..fdeca05 100644 --- a/server/main.go +++ b/server/main.go @@ -12,6 +12,20 @@ import ( //go:embed static/* var staticFS embed.FS +func loggingMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + slog.Info("request", "method", r.Method, "path", r.URL.Path) + next.ServeHTTP(w, r) + }) +} + +func cacheMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Cache-Control", "public, max-age=3600") + next.ServeHTTP(w, r) + }) +} + func main() { addr := flag.String("addr", ":8080", "listen address") flag.Parse() @@ -27,8 +41,7 @@ func main() { } fileServer := http.FileServer(http.FS(subFS)) - w.Header().Set("Cache-Control", "public, max-age=3600") - http.Handle("/", loggingMiddleware(fileServer)) + http.Handle("/", loggingMiddleware(cacheMiddleware(fileServer))) slog.Info("starting server", "addr", *addr) if err := http.ListenAndServe(*addr, nil); err != nil { |
