mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 12:45:47 +00:00
feat: allow customizability of resources dir
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user