mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 22:34:25 +01:00
Lower profiles' cache-control to 15min and notes' one to 24h
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"html"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
@@ -32,7 +33,7 @@ type Event struct {
|
||||
func render(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(r.URL.Path, ":~", r.Header.Get("user-agent"))
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Header().Set("Cache-Control", "max-age=604800")
|
||||
maxAge := 86400
|
||||
|
||||
code := r.URL.Path[1:]
|
||||
if strings.HasPrefix(code, "e/") {
|
||||
@@ -82,6 +83,7 @@ func render(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "error fetching event: "+err.Error(), 404)
|
||||
return
|
||||
}
|
||||
maxAge = 900
|
||||
} else {
|
||||
if event.Kind == 1 || event.Kind == 7 || event.Kind == 30023 {
|
||||
typ = "note"
|
||||
@@ -250,6 +252,8 @@ func render(w http.ResponseWriter, r *http.Request) {
|
||||
ParseFS(templates, "templates/*"),
|
||||
)
|
||||
|
||||
w.Header().Set("Cache-Control", "max-age="+strconv.Itoa(maxAge))
|
||||
|
||||
if err := tmpl.ExecuteTemplate(w, template_mapping[typ], params); err != nil {
|
||||
log.Error().Err(err).Msg("error rendering")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user