Skip to content

Commit

Permalink
Merge pull request #600 from signal18/caff_dev
Browse files Browse the repository at this point in the history
cache-static-files
  • Loading branch information
svaroqui authored May 23, 2024
2 parents aa89467 + 58d5236 commit 64b4045
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ type Config struct {
OAuthProvider string `mapstructure:"api-oauth-provider-url" toml:"api-oauth-provider-url" json:"apiOAuthProvider"`
OAuthClientID string `mapstructure:"api-oauth-client-id" toml:"api-oauth-client-id" json:"apiOAuthClientID"`
OAuthClientSecret string `mapstructure:"api-oauth-client-secret" toml:"api-oauth-client-secret" json:"apiOAuthClientSecret"`
CacheStaticMaxAge int `mapstructure:"cache-static-max-age" toml:"cache-static-max-age" json:"-"`
//OAuthRedirectURL string `mapstructure:"api-oauth-redirect-url" toml:"git-url" json:"-"`
// BackupResticStoragePolicy string `mapstructure:"backup-restic-storage-policy" toml:"backup-restic-storage-policy" json:"backupResticStoragePolicy"`
//ProvMode string `mapstructure:"prov-mode" toml:"prov-mode" json:"provMode"` //InitContainer vs API
Expand Down
12 changes: 11 additions & 1 deletion server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (repman *ReplicationManager) apiserver() {
router.PathPrefix("/app/").Handler(http.FileServer(http.Dir(repman.Conf.HttpRoot)))
} else {
router.HandleFunc("/", repman.rootHandler)
router.PathPrefix("/static/").Handler(repman.DashboardFSHandler())
router.PathPrefix("/static/").Handler(repman.handlerStatic(repman.DashboardFSHandler()))
router.PathPrefix("/app/").Handler(repman.DashboardFSHandler())
}

Expand Down Expand Up @@ -742,3 +742,13 @@ func (repman *ReplicationManager) handlerMuxMonitorHeartbeat(w http.ResponseWrit
panic(err)
}
}

func (repman *ReplicationManager) handlerStatic(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d", repman.Conf.CacheStaticMaxAge))
w.Header().Set("Etag", repman.Version)

h.ServeHTTP(w, r)
})
}
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ func (repman *ReplicationManager) AddFlags(flags *pflag.FlagSet, conf *config.Co

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

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

0 comments on commit 64b4045

Please sign in to comment.