feat: allow customizability of resources dir

This commit is contained in:
Stavros
2025-08-25 22:20:00 +03:00
parent 6418cbe2ba
commit 304c920b7b
4 changed files with 16 additions and 5 deletions

View File

@@ -113,6 +113,7 @@ func init() {
{"ldap-base-dn", "", "LDAP base DN (e.g. dc=example,dc=com)."},
{"ldap-insecure", false, "Skip certificate verification for the LDAP server."},
{"ldap-search-filter", "(uid=%s)", "LDAP search filter for user lookup."},
{"resources-dir", "/data/resources", "Path to a directory containing custom resources (e.g. background image)."},
}
for _, opt := range configOptions {

View File

@@ -151,7 +151,9 @@ func (app *BootstrapApp) Setup() error {
Domain: domain,
}, authService, oauthBrokerService)
uiMiddleware := middleware.NewUIMiddleware()
uiMiddleware := middleware.NewUIMiddleware(middleware.UIMiddlewareConfig{
ResourcesDir: app.Config.ResourcesDir,
})
zerologMiddleware := middleware.NewZerologMiddleware()
middlewares = append(middlewares, contextMiddleware, uiMiddleware, zerologMiddleware)

View File

@@ -55,6 +55,7 @@ type Config struct {
LdapBaseDN string `mapstructure:"ldap-base-dn"`
LdapInsecure bool `mapstructure:"ldap-insecure"`
LdapSearchFilter string `mapstructure:"ldap-search-filter"`
ResourcesDir string `mapstructure:"resources-dir"`
}
type OAuthLabels struct {

View File

@@ -10,14 +10,21 @@ import (
"github.com/gin-gonic/gin"
)
type UIMiddlewareConfig struct {
ResourcesDir string
}
type UIMiddleware struct {
Config UIMiddlewareConfig
UIFS fs.FS
UIFileServer http.Handler
ResourcesFileServer http.Handler
}
func NewUIMiddleware() *UIMiddleware {
return &UIMiddleware{}
func NewUIMiddleware(config UIMiddlewareConfig) *UIMiddleware {
return &UIMiddleware{
Config: config,
}
}
func (m *UIMiddleware) Init() error {
@@ -29,7 +36,7 @@ func (m *UIMiddleware) Init() error {
m.UIFS = ui
m.UIFileServer = http.FileServer(http.FS(ui))
m.ResourcesFileServer = http.FileServer(http.Dir("/data/resources"))
m.ResourcesFileServer = http.FileServer(http.Dir(m.Config.ResourcesDir))
return nil
}
@@ -45,7 +52,7 @@ func (m *UIMiddleware) Middleware() gin.HandlerFunc {
c.Next()
return
case "resources":
_, err := os.Stat("/data/resources/" + strings.TrimPrefix(c.Request.URL.Path, "/resources/"))
_, err := os.Stat(m.Config.ResourcesDir + strings.TrimPrefix(c.Request.URL.Path, "/resources/"))
if os.IsNotExist(err) {
c.Status(404)