mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-07 15:52:47 +01:00
Release catalyst
This commit is contained in:
24
static.go
Normal file
24
static.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package catalyst
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst/ui"
|
||||
)
|
||||
|
||||
func static(ctx *gin.Context) {
|
||||
fsys, _ := fs.Sub(ui.UI, "dist")
|
||||
|
||||
upath := strings.TrimPrefix(ctx.Request.URL.Path, "/")
|
||||
|
||||
if _, err := fs.Stat(fsys, upath); err != nil {
|
||||
ctx.Request.URL.Path = "/"
|
||||
ctx.Request.URL.RawPath = "/"
|
||||
}
|
||||
|
||||
http.FileServer(http.FS(fsys)).ServeHTTP(ctx.Writer, ctx.Request)
|
||||
}
|
||||
Reference in New Issue
Block a user