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) {
|
||||
|
||||
@@ -243,16 +243,8 @@ func handleSetup(c *gin.Context) {
|
||||
func checkConfigFile() bool {
|
||||
dataDir := config.GetDataDir()
|
||||
configPath := filepath.Join(dataDir, "config.yaml")
|
||||
if _, err := os.Stat(configPath); err == nil {
|
||||
return true
|
||||
}
|
||||
paths := []string{"config.yaml", "./config/config.yaml"}
|
||||
for _, p := range paths {
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
_, err := os.Stat(configPath)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func checkAdminExists() bool {
|
||||
|
||||
Reference in New Issue
Block a user