mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
0be883befb
* feat: customizable static assets This change provides the means to override specific assets from the embedded Go FS with files situated on disk. We only allow overriding the following files currently: * favicon.ico * logo.png * refactor(server): make logo string a const * refactor(suites): override favicon and use ntp3 in traefik2 suite * test(suites): test logo override in traefik2 suite * test(suites): test asset override fallback in traefik suite Closes #1630.
30 lines
717 B
Go
30 lines
717 B
Go
package middlewares
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
|
)
|
|
|
|
// AssetOverrideMiddleware allows overriding and serving of specific embedded assets from disk.
|
|
func AssetOverrideMiddleware(assetPath string, next fasthttp.RequestHandler) fasthttp.RequestHandler {
|
|
return func(ctx *fasthttp.RequestCtx) {
|
|
uri := string(ctx.RequestURI())
|
|
file := uri[strings.LastIndex(uri, "/")+1:]
|
|
|
|
if assetPath != "" && utils.IsStringInSlice(file, validOverrideAssets) {
|
|
_, err := os.Stat(assetPath + file)
|
|
if err != nil {
|
|
next(ctx)
|
|
} else {
|
|
fasthttp.FSHandler(assetPath, strings.Count(uri, "/")-1)(ctx)
|
|
}
|
|
} else {
|
|
next(ctx)
|
|
}
|
|
}
|
|
}
|