zwpanel/service/router/A_ENTER.go
2024-04-09 10:43:17 +08:00

49 lines
1.2 KiB
Go

package router
import (
"sun-panel/global"
// "sun-panel/router/admin"
"sun-panel/router/openness"
"sun-panel/router/panel"
"sun-panel/router/system"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
// 初始化总路由
func InitRouters(addr string) error {
router := gin.Default()
rootRouter := router.Group("/")
routerGroup := rootRouter.Group("api")
router.Use(cors.New(cors.Config{
// 允许所有源
AllowOrigins: []string{"*"},
// 允许所有方法
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
// 允许所有标头
AllowHeaders: []string{"*"},
}))
// 接口
system.Init(routerGroup)
panel.Init(routerGroup)
openness.Init(routerGroup)
// WEB文件服务
{
webPath := "./web"
router.StaticFile("/", webPath+"/index.html")
router.Static("/assets", webPath+"/assets")
router.Static("/custom", webPath+"/custom")
router.StaticFile("/favicon.ico", webPath+"/favicon.ico")
router.StaticFile("/favicon.svg", webPath+"/favicon.svg")
}
// 上传的文件
sourcePath := global.Config.GetValueString("base", "source_path")
router.Static(sourcePath[1:], sourcePath)
global.Logger.Info("Sun-Panel is Started. Listening and serving HTTP on ", addr)
return router.Run(addr)
}