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