mirror of
https://github.com/HexCardGames/HexDeck.git
synced 2025-09-05 11:18:38 +02:00
27 lines
529 B
Go
27 lines
529 B
Go
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)
|
|
}
|
|
}
|