summaryrefslogtreecommitdiff
path: root/system/admin
diff options
context:
space:
mode:
Diffstat (limited to 'system/admin')
-rw-r--r--system/admin/cache.go28
-rw-r--r--system/admin/server.go6
2 files changed, 4 insertions, 30 deletions
diff --git a/system/admin/cache.go b/system/admin/cache.go
deleted file mode 100644
index 2abdb26..0000000
--- a/system/admin/cache.go
+++ /dev/null
@@ -1,28 +0,0 @@
-package admin
-
-import (
- "fmt"
- "net/http"
- "strings"
-
- "github.com/bosssauce/ponzu/system/db"
-)
-
-// CacheControl sets the default cache policy on static asset responses
-func CacheControl(next http.Handler) http.Handler {
- return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
- etag := db.ConfigCache("etag")
- policy := fmt.Sprintf("max-age=%d, public, must-revalidate, proxy-revalidate", 60*60*24*30)
- res.Header().Add("Etag", etag)
- res.Header().Add("Cache-Control", policy)
-
- if match := res.Header().Get("If-None-Match"); match != "" {
- if strings.Contains(match, etag) {
- res.WriteHeader(http.StatusNotModified)
- return
- }
- }
-
- next.ServeHTTP(res, req)
- })
-}
diff --git a/system/admin/server.go b/system/admin/server.go
index f80a750..bc6f4d6 100644
--- a/system/admin/server.go
+++ b/system/admin/server.go
@@ -7,6 +7,8 @@ import (
"path/filepath"
"github.com/bosssauce/ponzu/system/admin/user"
+ "github.com/bosssauce/ponzu/system/api"
+ "github.com/bosssauce/ponzu/system/db"
)
// Run adds Handlers to default http listener for Admin
@@ -41,11 +43,11 @@ func Run() {
}
staticDir := filepath.Join(pwd, "cmd", "ponzu", "vendor", "github.com", "bosssauce", "ponzu", "system")
- http.Handle("/admin/static/", CacheControl(http.FileServer(restrict(http.Dir(staticDir)))))
+ http.Handle("/admin/static/", db.CacheControl(http.FileServer(restrict(http.Dir(staticDir)))))
// API path needs to be registered within server package so that it is handled
// even if the API server is not running. Otherwise, images/files uploaded
// through the editor will not load within the admin system.
uploadsDir := filepath.Join(pwd, "uploads")
- http.Handle("/api/uploads/", CacheControl(http.StripPrefix("/api/uploads/", http.FileServer(restrict(http.Dir(uploadsDir))))))
+ http.Handle("/api/uploads/", api.Record(db.CacheControl(http.StripPrefix("/api/uploads/", http.FileServer(restrict(http.Dir(uploadsDir)))))))
}