github.com/kuoss/venti@v0.2.20/pkg/handler/handle_spa.go (about) 1 package handler 2 3 import ( 4 "net/http" 5 6 "github.com/gin-gonic/contrib/static" 7 "github.com/gin-gonic/gin" 8 ) 9 10 func handleSPA() gin.HandlerFunc { 11 directory := static.LocalFile("./web/dist", true) 12 fileserver := http.StripPrefix("/", http.FileServer(directory)) 13 return func(c *gin.Context) { 14 if !directory.Exists("/", c.Request.URL.Path) { 15 c.Request.URL.Path = "/" 16 } 17 fileserver.ServeHTTP(c.Writer, c.Request) 18 c.Abort() 19 } 20 }