Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormhsanaei <ho3ein.sanaei@gmail.com>2025-09-12 14:04:36 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2025-09-12 14:04:36 +0300
commit311d11a3c1d0238816924d195fbb72372082ad9a (patch)
tree0053f692397aa412634c4a8f0ccfb0029dfc6f46 /web/web.go
parent40b6d7707a8d7856eb97e00ea7c86052859ce162 (diff)
cookie: MaxAge
and minor changes
Diffstat (limited to 'web/web.go')
-rw-r--r--web/web.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/web/web.go b/web/web.go
index 38eb24d6..35255104 100644
--- a/web/web.go
+++ b/web/web.go
@@ -31,7 +31,7 @@ import (
"github.com/robfig/cron/v3"
)
-//go:embed assets/*
+//go:embed assets
var assetsFS embed.FS
//go:embed html/*
@@ -180,6 +180,15 @@ func (s *Server) initRouter() (*gin.Engine, error) {
assetsBasePath := basePath + "assets/"
store := cookie.NewStore(secret)
+ // Configure default session cookie options, including expiration (MaxAge)
+ if sessionMaxAge, err := s.settingService.GetSessionMaxAge(); err == nil {
+ store.Options(sessions.Options{
+ Path: "/",
+ MaxAge: sessionMaxAge * 60, // minutes -> seconds
+ HttpOnly: true,
+ SameSite: http.SameSiteLaxMode,
+ })
+ }
engine.Use(sessions.Sessions("3x-ui", store))
engine.Use(func(c *gin.Context) {
c.Set("base_path", basePath)
@@ -201,7 +210,11 @@ func (s *Server) initRouter() (*gin.Engine, error) {
i18nWebFunc := func(key string, params ...string) string {
return locale.I18n(locale.Web, key, params...)
}
- engine.FuncMap["i18n"] = i18nWebFunc
+ // Register template functions before loading templates
+ funcMap := template.FuncMap{
+ "i18n": i18nWebFunc,
+ }
+ engine.SetFuncMap(funcMap)
engine.Use(locale.LocalizerMiddleware())
// set static files and template
@@ -211,11 +224,12 @@ func (s *Server) initRouter() (*gin.Engine, error) {
if err != nil {
return nil, err
}
+ // Use the registered func map with the loaded templates
engine.LoadHTMLFiles(files...)
engine.StaticFS(basePath+"assets", http.FS(os.DirFS("web/assets")))
} else {
// for production
- template, err := s.getHtmlTemplate(engine.FuncMap)
+ template, err := s.getHtmlTemplate(funcMap)
if err != nil {
return nil, err
}