2022-08-16 15:30:23 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
2023-05-29 16:00:56 +00:00
|
|
|
"github.com/gin-contrib/gzip"
|
2022-10-20 10:45:47 +00:00
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
|
2023-03-10 02:54:47 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2022-10-17 08:32:31 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/i18n"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/middleware"
|
|
|
|
rou "github.com/1Panel-dev/1Panel/backend/router"
|
2022-12-14 11:39:32 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/cmd/server/docs"
|
2022-10-17 09:13:47 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/cmd/server/web"
|
2022-08-16 15:30:23 +00:00
|
|
|
ginI18n "github.com/gin-contrib/i18n"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
swaggerfiles "github.com/swaggo/files"
|
|
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
|
|
|
)
|
|
|
|
|
2023-05-29 16:00:56 +00:00
|
|
|
func setWebStatic(rootRouter *gin.RouterGroup) {
|
2023-06-07 08:31:25 +00:00
|
|
|
rootRouter.StaticFS("/public", http.FS(web.Favicon))
|
2022-10-17 09:13:47 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-08-16 15:30:23 +00:00
|
|
|
func Routers() *gin.Engine {
|
|
|
|
Router := gin.Default()
|
2022-12-13 10:54:28 +00:00
|
|
|
Router.Use(middleware.OperationLog())
|
2022-12-18 15:00:24 +00:00
|
|
|
// Router.Use(middleware.CSRF())
|
|
|
|
// Router.Use(middleware.LoadCsrfToken())
|
2023-02-21 07:19:12 +00:00
|
|
|
if global.CONF.System.IsDemo {
|
|
|
|
Router.Use(middleware.DemoHandle())
|
|
|
|
}
|
2023-05-29 16:00:56 +00:00
|
|
|
|
|
|
|
Router.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()
|
|
|
|
})
|
|
|
|
|
2022-08-16 15:30:23 +00:00
|
|
|
Router.Use(i18n.GinI18nLocalize())
|
|
|
|
Router.SetFuncMap(template.FuncMap{
|
|
|
|
"Localize": ginI18n.GetMessage,
|
|
|
|
})
|
|
|
|
|
|
|
|
systemRouter := rou.RouterGroupApp
|
2023-03-29 03:46:14 +00:00
|
|
|
swaggerRouter := Router.Group("1panel")
|
|
|
|
docs.SwaggerInfo.BasePath = "/api/v1"
|
|
|
|
swaggerRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
|
2022-08-16 15:30:23 +00:00
|
|
|
PublicGroup := Router.Group("")
|
|
|
|
{
|
|
|
|
PublicGroup.GET("/health", func(c *gin.Context) {
|
|
|
|
c.JSON(200, "ok")
|
|
|
|
})
|
2023-05-29 16:00:56 +00:00
|
|
|
PublicGroup.Use(gzip.Gzip(gzip.DefaultCompression))
|
|
|
|
setWebStatic(PublicGroup)
|
2022-08-16 15:30:23 +00:00
|
|
|
}
|
|
|
|
PrivateGroup := Router.Group("/api/v1")
|
2023-05-19 13:47:46 +00:00
|
|
|
PrivateGroup.Use(middleware.WhiteAllow())
|
|
|
|
PrivateGroup.Use(middleware.BindDomain())
|
2023-01-31 07:22:05 +00:00
|
|
|
PrivateGroup.Use(middleware.GlobalLoading())
|
2022-08-16 15:30:23 +00:00
|
|
|
{
|
|
|
|
systemRouter.InitBaseRouter(PrivateGroup)
|
2022-11-24 15:56:48 +00:00
|
|
|
systemRouter.InitDashboardRouter(PrivateGroup)
|
2022-08-18 10:54:21 +00:00
|
|
|
systemRouter.InitHostRouter(PrivateGroup)
|
2022-10-08 10:32:02 +00:00
|
|
|
systemRouter.InitContainerRouter(PrivateGroup)
|
2022-08-17 11:02:48 +00:00
|
|
|
systemRouter.InitTerminalRouter(PrivateGroup)
|
2022-09-08 03:39:14 +00:00
|
|
|
systemRouter.InitMonitorRouter(PrivateGroup)
|
2022-11-15 09:20:57 +00:00
|
|
|
systemRouter.InitLogRouter(PrivateGroup)
|
2022-08-24 03:10:50 +00:00
|
|
|
systemRouter.InitFileRouter(PrivateGroup)
|
2022-09-20 11:12:48 +00:00
|
|
|
systemRouter.InitCronjobRouter(PrivateGroup)
|
2022-09-15 02:44:43 +00:00
|
|
|
systemRouter.InitSettingRouter(PrivateGroup)
|
2022-09-22 08:16:04 +00:00
|
|
|
systemRouter.InitAppRouter(PrivateGroup)
|
2022-10-28 09:04:57 +00:00
|
|
|
systemRouter.InitWebsiteRouter(PrivateGroup)
|
|
|
|
systemRouter.InitWebsiteGroupRouter(PrivateGroup)
|
2022-11-10 09:44:38 +00:00
|
|
|
systemRouter.InitWebsiteDnsAccountRouter(PrivateGroup)
|
2022-10-20 10:45:47 +00:00
|
|
|
systemRouter.InitDatabaseRouter(PrivateGroup)
|
2022-11-16 02:31:35 +00:00
|
|
|
systemRouter.InitWebsiteSSLRouter(PrivateGroup)
|
2022-11-11 09:41:39 +00:00
|
|
|
systemRouter.InitWebsiteAcmeAccountRouter(PrivateGroup)
|
2022-11-23 08:19:05 +00:00
|
|
|
systemRouter.InitNginxRouter(PrivateGroup)
|
2023-03-29 06:58:28 +00:00
|
|
|
systemRouter.InitRuntimeRouter(PrivateGroup)
|
2023-06-28 06:50:10 +00:00
|
|
|
systemRouter.InitProcessRouter(PrivateGroup)
|
2022-08-16 15:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Router
|
|
|
|
}
|