mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-04 23:45:07 +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:
parent
734cfdddae
commit
5571db3e1b
@ -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
|
||||
|
||||
|
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:
|
||||
ShortCache:
|
||||
MaxAge: 5m
|
||||
SharedMaxAge: 15m
|
||||
MaxAge: 0m
|
||||
SharedMaxAge: 5m
|
||||
LongCache:
|
||||
MaxAge: 12h
|
||||
SharedMaxAge: 168h
|
||||
|
@ -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, ".")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user