Skip to content

Commit

Permalink
feat(backend|frontend): Gzip and cache headers (helm#205)
Browse files Browse the repository at this point in the history
* Add gzip

* Enable Gzip

* Enable Gzip
  • Loading branch information
migmartri authored and prydonius committed Mar 3, 2017
1 parent 437497d commit 553df42
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions deployment/monocular/templates/ui-vhost.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ data:
server {
listen 80;
gzip on;
# Angular CLI already has gzipped the assets (ng build --prod --aot)
gzip_static on;
location / {
try_files $uri @prerender;
Expand Down
10 changes: 8 additions & 2 deletions src/api/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/api/glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ import:
version: ~1.2.2
- package: github.com/Sirupsen/logrus
version: ^0.11.4
- package: github.com/NYTimes/gziphandler
6 changes: 5 additions & 1 deletion src/api/swagger/restapi/configure_monocular.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/NYTimes/gziphandler"
errors "github.com/go-openapi/errors"
runtime "github.com/go-openapi/runtime"
middleware "github.com/go-openapi/runtime/middleware"
Expand Down Expand Up @@ -98,6 +99,7 @@ func setupMiddlewares(handler http.Handler) http.Handler {
func setupGlobalMiddleware(handler http.Handler) http.Handler {
handler = setupStaticFilesMiddleware(handler)
handler = setupCorsMiddleware(handler)
handler = gziphandler.GzipHandler(handler)
return handler
}

Expand All @@ -106,7 +108,9 @@ func setupStaticFilesMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Returns static files under /static
if strings.Index(r.URL.Path, "/assets/") == 0 {
fs := http.StripPrefix("/assets/", http.FileServer(http.Dir(charthelper.DataDirBase())))
w.Header().Set("Cache-Control", "public, max-age=7776000")
fs := http.FileServer(http.Dir(charthelper.DataDirBase()))
fs = http.StripPrefix("/assets/", fs)
fs.ServeHTTP(w, r)
} else {
// Fallbacks to chained hander
Expand Down

0 comments on commit 553df42

Please sign in to comment.