diff --git a/backend/init/router/router.go b/backend/init/router/router.go index 63eaedc0d..642116b1a 100644 --- a/backend/init/router/router.go +++ b/backend/init/router/router.go @@ -6,18 +6,41 @@ import ( "github.com/1Panel-dev/1Panel/backend/i18n" "github.com/1Panel-dev/1Panel/backend/middleware" rou "github.com/1Panel-dev/1Panel/backend/router" + "github.com/1Panel-dev/1Panel/cmd/server/web" ginI18n "github.com/gin-contrib/i18n" "github.com/gin-gonic/gin" swaggerfiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" "html/template" + "net/http" ) +func setWebStatic(rootRouter *gin.Engine) { + rootRouter.StaticFS("/kubepi/login/onepanel", http.FS(web.IndexHtml)) + rootRouter.StaticFS("/favicon.ico", http.FS(web.Favicon)) + rootRouter.GET("/assets/*filepath", func(c *gin.Context) { + staticServer := http.FileServer(http.FS(web.Assets)) + staticServer.ServeHTTP(c.Writer, c.Request) + }) + + rootRouter.GET("/", func(c *gin.Context) { + staticServer := http.FileServer(http.FS(web.IndexHtml)) + staticServer.ServeHTTP(c.Writer, c.Request) + }) + rootRouter.NoRoute(func(c *gin.Context) { + c.Writer.WriteHeader(http.StatusOK) + c.Writer.Write(web.IndexByte) + c.Writer.Header().Add("Accept", "text/html") + c.Writer.Flush() + }) +} + func Routers() *gin.Engine { Router := gin.Default() - Router.Use(middleware.CSRF()) - Router.Use(middleware.LoadCsrfToken()) + //Router.Use(middleware.CSRF()) + //Router.Use(middleware.LoadCsrfToken()) + setWebStatic(Router) docs.SwaggerInfo.BasePath = "/api/v1" Router.Use(i18n.GinI18nLocalize()) diff --git a/backend/server/server.go b/backend/server/server.go index 0b22ade59..2d4f0b56a 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -3,8 +3,6 @@ package server import ( "encoding/gob" "fmt" - "github.com/1Panel-dev/1Panel/cmd/server/web" - "net/http" "time" "github.com/1Panel-dev/1Panel/backend/cron" @@ -38,14 +36,6 @@ func Start() { rootRouter := router.Routers() address := fmt.Sprintf(":%d", global.CONF.System.Port) - rootRouter.StaticFS("/login/onepanel", http.FS(web.IndexHtml)) - rootRouter.StaticFS("/1panel", http.FS(web.IndexHtml)) - - rootRouter.GET("/assets/*filepath", func(c *gin.Context) { - staticServer := http.FileServer(http.FS(web.Assets)) - staticServer.ServeHTTP(c.Writer, c.Request) - }) - s := initServer(address, rootRouter) global.LOG.Infof("server run success on %d", global.CONF.System.Port) if err := s.ListenAndServe(); err != nil { diff --git a/cmd/server/web/static.go b/cmd/server/web/static.go index 73f8939af..f7ccfdfbd 100644 --- a/cmd/server/web/static.go +++ b/cmd/server/web/static.go @@ -7,3 +7,9 @@ var IndexHtml embed.FS //go:embed assets/* var Assets embed.FS + +//go:embed index.html +var IndexByte []byte + +//go:embed favicon.ico +var Favicon embed.FS diff --git a/frontend/src/routers/router.ts b/frontend/src/routers/router.ts index b06c47eb8..2a5de3ac6 100644 --- a/frontend/src/routers/router.ts +++ b/frontend/src/routers/router.ts @@ -71,7 +71,7 @@ export const routes: RouteRecordRaw[] = [ }, ]; const router = createRouter({ - history: createWebHistory('/kubepi/'), + history: createWebHistory('/1panel/'), routes: routes as RouteRecordRaw[], strict: false, scrollBehavior: () => ({ left: 0, top: 0 }),