Permalink
Browse files

feat(api): introduce cache busting mechanism (#439)

  • Loading branch information...
1 parent ecc8857 commit 6e98237419b9f176cb1f9c44373dbf1eb8fd67ec @deviantony deviantony committed on GitHub Dec 30, 2016
Showing with 466 additions and 395 deletions.
  1. +1 −0 .gitignore
  2. +20 −0 api/http/file_handler.go
  3. +1 −1 api/http/handler.go
  4. +1 −1 api/http/server.go
  5. +0 −390 gruntFile.js
  6. +433 −0 gruntfile.js
  7. +6 −2 index.html
  8. +4 −1 package.json
View
@@ -3,3 +3,4 @@ bower_components
dist
portainer-checksum.txt
api/cmd/portainer/portainer*
+.tmp
@@ -0,0 +1,20 @@
+package http
+
+import "net/http"
+
+// FileHandler represents an HTTP API handler for managing static files.
+type FileHandler struct {
+ http.Handler
+}
+
+func newFileHandler(assetPath string) *FileHandler {
+ h := &FileHandler{
+ Handler: http.FileServer(http.Dir(assetPath)),
+ }
+ return h
+}
+
+func (fileHandler *FileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Cache-Control", "max-age=31536000")
+ fileHandler.Handler.ServeHTTP(w, r)
+}
View
@@ -19,7 +19,7 @@ type Handler struct {
DockerHandler *DockerHandler
WebSocketHandler *WebSocketHandler
UploadHandler *UploadHandler
- FileHandler http.Handler
+ FileHandler *FileHandler
}
const (
View
@@ -63,7 +63,7 @@ func (server *Server) Start() error {
endpointHandler.server = server
var uploadHandler = NewUploadHandler(middleWareService)
uploadHandler.FileService = server.FileService
- var fileHandler = http.FileServer(http.Dir(server.AssetsPath))
+ var fileHandler = newFileHandler(server.AssetsPath)
server.Handler = &Handler{
AuthHandler: authHandler,
Oops, something went wrong.

0 comments on commit 6e98237

Please sign in to comment.