Fix SPA routing and static file paths
This commit is contained in:
@@ -27,8 +27,6 @@ func SetupRoutes(r *gin.Engine) {
|
||||
|
||||
r.Use(middlewares.CORSMiddleware())
|
||||
|
||||
r.Static("/uploads", "./uploads")
|
||||
|
||||
api := r.Group("/api")
|
||||
{
|
||||
api.GET("/installed", authHandler.CheckInstalled)
|
||||
@@ -204,4 +202,24 @@ func SetupRoutes(r *gin.Engine) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Serve uploads
|
||||
r.Static("/uploads", "./uploads")
|
||||
|
||||
// SPA fallback - serve index.html for all other routes (Vue Router History Mode)
|
||||
// This must be the last route to catch all unmatched paths
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
path := c.Request.URL.Path
|
||||
// Serve index.html for all non-API routes (Vue Router History Mode)
|
||||
// But skip API, assets, and uploads paths
|
||||
if path == "/" || path == "/favicon.ico" || path == "/icons.svg" || path == "/favicon.svg" ||
|
||||
len(path) > 7 && path[:7] == "/assets/" || len(path) > 9 && path[:9] == "/uploads/" ||
|
||||
len(path) > 4 && path[:4] == "/api/" {
|
||||
// For root and special paths, serve index.html directly
|
||||
c.File("/app/static/index.html")
|
||||
} else {
|
||||
// For all other routes, serve index.html (Vue Router handles client-side routing)
|
||||
c.File("/app/static/index.html")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user