Skip to content

Commit 58d5236

Browse files
committed
cache-static-files
1 parent aa89467 commit 58d5236

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ type Config struct {
653653
OAuthProvider string `mapstructure:"api-oauth-provider-url" toml:"api-oauth-provider-url" json:"apiOAuthProvider"`
654654
OAuthClientID string `mapstructure:"api-oauth-client-id" toml:"api-oauth-client-id" json:"apiOAuthClientID"`
655655
OAuthClientSecret string `mapstructure:"api-oauth-client-secret" toml:"api-oauth-client-secret" json:"apiOAuthClientSecret"`
656+
CacheStaticMaxAge int `mapstructure:"cache-static-max-age" toml:"cache-static-max-age" json:"-"`
656657
//OAuthRedirectURL string `mapstructure:"api-oauth-redirect-url" toml:"git-url" json:"-"`
657658
// BackupResticStoragePolicy string `mapstructure:"backup-restic-storage-policy" toml:"backup-restic-storage-policy" json:"backupResticStoragePolicy"`
658659
//ProvMode string `mapstructure:"prov-mode" toml:"prov-mode" json:"provMode"` //InitContainer vs API

server/api.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (repman *ReplicationManager) apiserver() {
149149
router.PathPrefix("/app/").Handler(http.FileServer(http.Dir(repman.Conf.HttpRoot)))
150150
} else {
151151
router.HandleFunc("/", repman.rootHandler)
152-
router.PathPrefix("/static/").Handler(repman.DashboardFSHandler())
152+
router.PathPrefix("/static/").Handler(repman.handlerStatic(repman.DashboardFSHandler()))
153153
router.PathPrefix("/app/").Handler(repman.DashboardFSHandler())
154154
}
155155

@@ -742,3 +742,13 @@ func (repman *ReplicationManager) handlerMuxMonitorHeartbeat(w http.ResponseWrit
742742
panic(err)
743743
}
744744
}
745+
746+
func (repman *ReplicationManager) handlerStatic(h http.Handler) http.Handler {
747+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
748+
749+
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d", repman.Conf.CacheStaticMaxAge))
750+
w.Header().Set("Etag", repman.Version)
751+
752+
h.ServeHTTP(w, r)
753+
})
754+
}

server/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ func (repman *ReplicationManager) AddFlags(flags *pflag.FlagSet, conf *config.Co
418418

419419
//flags.BoolVar(&conf.Daemon, "daemon", true, "Daemon mode. Do not start the Termbox console")
420420
conf.Daemon = true
421+
flags.IntVar(&conf.CacheStaticMaxAge, "cache-static-max-age", 18000, "Cache Max Age Duration for static files")
421422

422423
if WithEnforce == "ON" {
423424
flags.BoolVar(&conf.ForceSlaveReadOnly, "force-slave-readonly", true, "Automatically activate read only on slave")

0 commit comments

Comments
 (0)