set /raw/ to cache

This commit is contained in:
Bel LaPointe
2024-01-09 15:04:51 -07:00
parent 5b645b1898
commit 0a700f19c8
4 changed files with 235 additions and 10 deletions

View File

@@ -2,12 +2,13 @@ package server
import (
"fmt"
"gitea.inhome.blapointe.com/local/gziphttp"
"gitea.inhome.blapointe.com/local/notes-server/config"
"gitea.inhome.blapointe.com/local/router"
"net/http"
"path/filepath"
"strings"
"gitea.inhome.blapointe.com/local/gziphttp"
"gitea.inhome.blapointe.com/local/notes-server/config"
"gitea.inhome.blapointe.com/local/router"
)
func (s *Server) Routes() error {
@@ -19,7 +20,7 @@ func (s *Server) Routes() error {
handler: s.root,
},
fmt.Sprintf("raw/%s%s", wildcard, wildcard): {
handler: s.gzip(s.authenticate(s.raw)),
handler: s.gzip(s.authenticate(s.cached(s.raw))),
},
fmt.Sprintf("notes/%s%s", wildcard, wildcard): {
handler: s.gzip(s.authenticate(s.notes)),

View File

@@ -1,12 +1,13 @@
package server
import (
"log"
"net/http"
"gitea.inhome.blapointe.com/local/notes-server/config"
"gitea.inhome.blapointe.com/local/notes-server/notes"
"gitea.inhome.blapointe.com/local/oauth2/oauth2client"
"gitea.inhome.blapointe.com/local/router"
"log"
"net/http"
)
type Server struct {
@@ -21,6 +22,13 @@ func New() *Server {
}
}
func (s *Server) cached(foo http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "private, max-age=7776000")
foo(w, r)
}
}
func (s *Server) authenticate(foo http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if config.OAuthServer != "" {