The attodo.app, uhh... app.
1package middleware
2
3import (
4 "net/http"
5
6 "github.com/shindakun/attodo/internal/config"
7)
8
9// NoCacheMiddleware adds cache control headers to prevent caching in dev mode
10func NoCacheMiddleware(cfg *config.Config, next http.Handler) http.Handler {
11 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
12 if cfg.IsDev() {
13 // Prevent all caching in development mode
14 w.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate")
15 w.Header().Set("Pragma", "no-cache")
16 w.Header().Set("Expires", "0")
17 }
18 next.ServeHTTP(w, r)
19 })
20}