Skip to content

Commit

Permalink
Add cache-control header to images
Browse files Browse the repository at this point in the history
  • Loading branch information
rcy committed Dec 12, 2024
1 parent 041597d commit 4dadf7c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,12 @@ func Serve(db *sqlx.DB, b *bot.Bot) {
})

fs := http.FileServer(http.Dir(image.ImageFileBase))
r.Handle("/images/*", http.StripPrefix("/images/", fs))
r.Handle("/images/*",
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%.0f", (time.Hour*24*365).Seconds()))
http.StripPrefix("/images/", fs).ServeHTTP(w, r)
}),
)

addr := ":" + os.Getenv("PORT")
log.Printf("web server listening on %s", addr)
Expand Down

0 comments on commit 4dadf7c

Please sign in to comment.