Add caching for static web assets

This commit is contained in:
Benedikt Kulmann
2020-11-16 23:22:56 +01:00
parent aaf9029a3e
commit 9c6dac8328
10 changed files with 50 additions and 5 deletions
+1
View File
@@ -20,6 +20,7 @@ type HTTP struct {
Addr string
Namespace string
Root string
CacheTTL int
}
// GRPC defines the available grpc configuration.
+7
View File
@@ -136,6 +136,13 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"SETTINGS_HTTP_ROOT"},
Destination: &cfg.HTTP.Root,
},
&cli.IntFlag{
Name: "http-cache-ttl",
Value: 604800, // 7 days
Usage: "Set the static assets caching duration in seconds",
EnvVars: []string{"SETTINGS_CACHE_TTL"},
Destination: &cfg.HTTP.CacheTTL,
},
&cli.StringFlag{
Name: "grpc-addr",
Value: "0.0.0.0:9191",
+1
View File
@@ -60,6 +60,7 @@ func Server(opts ...Option) http.Service {
assets.Logger(options.Logger),
assets.Config(options.Config),
),
options.Config.HTTP.CacheTTL,
))
mux.Route(options.Config.HTTP.Root, func(r chi.Router) {