fix: 嵌入式前端正确服务world.json等静态文件
- 修复/install路由返回登录页问题 - checkConfigFile只检查数据目录 - setupEmbeddedFrontend正确响应项目目录下文件
This commit is contained in:
+19
-7
@@ -261,17 +261,29 @@ func setupEmbeddedFrontend(r *gin.Engine) {
|
||||
return
|
||||
}
|
||||
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
if c.Request.Method == "GET" && !strings.HasPrefix(c.Request.URL.Path, "/api/") {
|
||||
serveIndexHTML(c, string(indexHTML))
|
||||
return
|
||||
}
|
||||
c.JSON(404, gin.H{"error": "not found"})
|
||||
})
|
||||
fileServer := http.FileServer(http.FS(distFS))
|
||||
|
||||
r.GET("/assets/*filepath", func(c *gin.Context) {
|
||||
c.FileFromFS(c.Request.URL.Path, http.FS(distFS))
|
||||
})
|
||||
|
||||
r.GET("/*filepath", func(c *gin.Context) {
|
||||
path := c.Param("filepath")
|
||||
if path == "" || path == "/" {
|
||||
serveIndexHTML(c, string(indexHTML))
|
||||
return
|
||||
}
|
||||
path = strings.TrimPrefix(path, "/")
|
||||
|
||||
f, err := distFS.Open(path)
|
||||
if err == nil {
|
||||
f.Close()
|
||||
fileServer.ServeHTTP(c.Writer, c.Request)
|
||||
return
|
||||
}
|
||||
|
||||
serveIndexHTML(c, string(indexHTML))
|
||||
})
|
||||
}
|
||||
|
||||
func serveIndexHTML(c *gin.Context, indexHTML string) {
|
||||
|
||||
Reference in New Issue
Block a user