diff --git a/.goreleaser.yaml b/.goreleaser.yaml index ad8c2726a..e1187f3bf 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -27,6 +27,8 @@ builds: goarch: - amd64 - arm64 + ldflags: + -s -w -X github.com/zitadel/zitadel/cmd/build.version={{.Version}} -X github.com/zitadel/zitadel/cmd/build.commit={{.Commit}} -X github.com/zitadel/zitadel/cmd/build.date={{.Date}} dist: .artifacts/goreleaser diff --git a/cmd/build/info.go b/cmd/build/info.go new file mode 100644 index 000000000..aa91a25fb --- /dev/null +++ b/cmd/build/info.go @@ -0,0 +1,29 @@ +package build + +import "time" + +var ( + version = "" + commit = "" + date = "" + dateTime time.Time +) + +func Version() string { + return version +} + +func Commit() string { + return commit +} + +func Date() time.Time { + if !dateTime.IsZero() { + return dateTime + } + dateTime, _ = time.Parse(time.RFC3339, date) + if dateTime.IsZero() { + dateTime = time.Now() + } + return dateTime +} diff --git a/cmd/defaults.yaml b/cmd/defaults.yaml index 98aad55b5..ef8dcb34c 100644 --- a/cmd/defaults.yaml +++ b/cmd/defaults.yaml @@ -98,8 +98,8 @@ Login: Console: ShortCache: - MaxAge: 5m - SharedMaxAge: 15m + MaxAge: 0m + SharedMaxAge: 5m LongCache: MaxAge: 12h SharedMaxAge: 168h diff --git a/internal/api/ui/console/console.go b/internal/api/ui/console/console.go index 9ebb5c30f..e219edd6b 100644 --- a/internal/api/ui/console/console.go +++ b/internal/api/ui/console/console.go @@ -8,12 +8,14 @@ import ( "net/http" "os" "path" + "strings" "time" "github.com/gorilla/mux" "github.com/zitadel/logging" "github.com/zitadel/oidc/v2/pkg/op" + "github.com/zitadel/zitadel/cmd/build" "github.com/zitadel/zitadel/internal/api/authz" http_util "github.com/zitadel/zitadel/internal/api/http" "github.com/zitadel/zitadel/internal/api/http/middleware" @@ -56,7 +58,30 @@ func (i *spaHandler) Open(name string) (http.File, error) { return ret, err } - return i.fileSystem.Open("/index.html") + f, err := i.fileSystem.Open("/index.html") + if err != nil { + return nil, err + } + return &file{File: f}, nil +} + +//file wraps the http.File and fs.FileInfo interfaces +//to return the build.Date() as ModTime() of the file +type file struct { + http.File + fs.FileInfo +} + +func (f *file) ModTime() time.Time { + return build.Date() +} + +func (f *file) Stat() (_ fs.FileInfo, err error) { + f.FileInfo, err = f.File.Stat() + if err != nil { + return nil, err + } + return f, nil } func Start(config Config, externalSecure bool, issuer op.IssuerFromRequest, instanceHandler func(http.Handler) http.Handler) (http.Handler, error) { @@ -119,7 +144,7 @@ func assetsCacheInterceptorIgnoreManifest(shortMaxAge, shortSharedMaxAge, longMa return func(handler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { for _, file := range shortCacheFiles { - if r.URL.Path == file { + if r.URL.Path == file || isIndexOrSubPath(r.URL.Path) { middleware.AssetsCacheInterceptor(shortMaxAge, shortSharedMaxAge, handler).ServeHTTP(w, r) return } @@ -129,3 +154,8 @@ func assetsCacheInterceptorIgnoreManifest(shortMaxAge, shortSharedMaxAge, longMa }) } } + +func isIndexOrSubPath(path string) bool { + //files will have an extension + return !strings.Contains(path, ".") +} diff --git a/main.go b/main.go index 0d769bb6a..0f3264080 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "os" "github.com/spf13/cobra" + "github.com/zitadel/zitadel/cmd" )