使用VUE重构项目
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -299,30 +300,31 @@ func registerAdminRoutesV2(v2 *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
func registerWebRoutes(router *gin.Engine) {
|
||||
themeRoot := filepath.Join(".", "frontend", "theme")
|
||||
adminRoot := filepath.Join(".", "frontend", "admin")
|
||||
adminRoot := filepath.Join(".", "frontend", "admin", "dist")
|
||||
|
||||
if _, err := os.Stat(themeRoot); err == nil {
|
||||
router.Static("/theme", themeRoot)
|
||||
}
|
||||
if _, err := os.Stat(adminRoot); err == nil {
|
||||
router.Static("/admin-assets", adminRoot)
|
||||
}
|
||||
|
||||
securePath := "/" + service.GetAdminSecurePath()
|
||||
subscribePath := "/" + service.GetSubscribePath()
|
||||
router.GET("/", handler.UserThemePage)
|
||||
router.GET("/dashboard", handler.UserThemePage)
|
||||
|
||||
// Redirect root to admin if needed, or just 404
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
c.Redirect(http.StatusTemporaryRedirect, securePath)
|
||||
})
|
||||
|
||||
router.GET(subscribePath+"/:token", handler.Subscribe)
|
||||
router.GET(securePath, handler.AdminAppPage)
|
||||
router.GET(securePath+"/", handler.AdminAppPage)
|
||||
router.GET(securePath+"/plugin-panel/:kind", handler.AdminPluginPanelPage)
|
||||
router.GET(securePath+"/plugins/:plugin", handler.AdminAppPage)
|
||||
|
||||
// Serve Vue admin panel index.html for all admin-related routes (SPA)
|
||||
router.NoRoute(func(c *gin.Context) {
|
||||
path := c.Request.URL.Path
|
||||
if path == securePath || strings.HasPrefix(path, securePath+"/") {
|
||||
handler.AdminAppPage(c)
|
||||
return
|
||||
indexFile := filepath.Join(adminRoot, "index.html")
|
||||
if _, err := os.Stat(indexFile); err == nil {
|
||||
c.File(indexFile)
|
||||
return
|
||||
}
|
||||
}
|
||||
c.JSON(404, gin.H{"message": "not found"})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user