mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 23:27:31 +00:00
feat: improve console caching and provide build info (#3621)
* feat: improve console caching and provide build info * Update info.go
This commit is contained in:
@@ -27,6 +27,8 @@ builds:
|
|||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
- arm64
|
- 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
|
dist: .artifacts/goreleaser
|
||||||
|
|
||||||
|
29
cmd/build/info.go
Normal file
29
cmd/build/info.go
Normal file
@@ -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
|
||||||
|
}
|
@@ -98,8 +98,8 @@ Login:
|
|||||||
|
|
||||||
Console:
|
Console:
|
||||||
ShortCache:
|
ShortCache:
|
||||||
MaxAge: 5m
|
MaxAge: 0m
|
||||||
SharedMaxAge: 15m
|
SharedMaxAge: 5m
|
||||||
LongCache:
|
LongCache:
|
||||||
MaxAge: 12h
|
MaxAge: 12h
|
||||||
SharedMaxAge: 168h
|
SharedMaxAge: 168h
|
||||||
|
@@ -8,12 +8,14 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/zitadel/logging"
|
"github.com/zitadel/logging"
|
||||||
"github.com/zitadel/oidc/v2/pkg/op"
|
"github.com/zitadel/oidc/v2/pkg/op"
|
||||||
|
|
||||||
|
"github.com/zitadel/zitadel/cmd/build"
|
||||||
"github.com/zitadel/zitadel/internal/api/authz"
|
"github.com/zitadel/zitadel/internal/api/authz"
|
||||||
http_util "github.com/zitadel/zitadel/internal/api/http"
|
http_util "github.com/zitadel/zitadel/internal/api/http"
|
||||||
"github.com/zitadel/zitadel/internal/api/http/middleware"
|
"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 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) {
|
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 func(handler http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
for _, file := range shortCacheFiles {
|
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)
|
middleware.AssetsCacheInterceptor(shortMaxAge, shortSharedMaxAge, handler).ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -129,3 +154,8 @@ func assetsCacheInterceptorIgnoreManifest(shortMaxAge, shortSharedMaxAge, longMa
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isIndexOrSubPath(path string) bool {
|
||||||
|
//files will have an extension
|
||||||
|
return !strings.Contains(path, ".")
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user