diff --git a/apis/tpl/tpl.go b/apis/tpl/tpl.go new file mode 100644 index 0000000..e659d5f --- /dev/null +++ b/apis/tpl/tpl.go @@ -0,0 +1,15 @@ +package tpl + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +/* + @Author : lanyulei +*/ + +func Tpl(c *gin.Context) { + c.HTML(http.StatusOK, "index.html", gin.H{}) +} diff --git a/router/router.go b/router/router.go index 701f28a..dfd4e0a 100644 --- a/router/router.go +++ b/router/router.go @@ -1,6 +1,7 @@ package router import ( + "ferry/apis/tpl" "ferry/pkg/jwtauth" "ferry/router/dashboard" "ferry/router/process" @@ -19,7 +20,7 @@ func InitSysRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) *gin systemRouter.SysBaseRouter(g) // 静态文件 - sysStaticFileRouter(g) + sysStaticFileRouter(g, r) // swagger;注意:生产环境可以注释掉 sysSwaggerRouter(g) @@ -33,8 +34,9 @@ func InitSysRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) *gin return g } -func sysStaticFileRouter(r *gin.RouterGroup) { +func sysStaticFileRouter(r *gin.RouterGroup, g *gin.Engine) { r.Static("/static", "./static") + g.LoadHTMLGlob("template/web/index.html") } func sysSwaggerRouter(r *gin.RouterGroup) { @@ -48,6 +50,9 @@ func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwtauth.GinJWTMi v1 := r.Group("/api/v1") + // 兼容前后端不分离的情 + r.GET("/", tpl.Tpl) + // 首页 dashboard.RegisterDashboardRouter(v1, authMiddleware) diff --git a/router/system/sys_router.go b/router/system/sys_router.go index e466364..23bf18c 100644 --- a/router/system/sys_router.go +++ b/router/system/sys_router.go @@ -14,7 +14,7 @@ import ( ) func SysBaseRouter(r *gin.RouterGroup) { - r.GET("/", system.HelloWorld) + //r.GET("/", system.HelloWorld) r.GET("/info", handler.Ping) }