mirror of
https://github.com/HexCardGames/HexDeck.git
synced 2025-09-05 19:18:39 +02:00
feat(backend): serve static frontend files
This commit is contained in:
26
backend/api/static.go
Normal file
26
backend/api/static.go
Normal file
@ -0,0 +1,26 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func SPAMiddleware(fs embed.FS, prefix string, notFoundPath string) gin.HandlerFunc {
|
||||
fileServer := http.FileServerFS(fs)
|
||||
|
||||
return func(c *gin.Context) {
|
||||
if strings.HasPrefix(c.Request.URL.Path, "/api/") {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
c.Request.URL.Path = prefix + c.Request.URL.Path
|
||||
_, err := fs.Open(c.Request.URL.Path)
|
||||
if err != nil {
|
||||
c.Request.URL.Path = prefix + notFoundPath
|
||||
}
|
||||
fileServer.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user