From 65b8090ad0f32c84fe02e19b042d25d846d89977 Mon Sep 17 00:00:00 2001 From: "Mr. Lan" Date: Tue, 13 Oct 2020 00:14:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=BC=E5=AE=B9=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E4=B8=8D=E5=88=86=E7=A6=BB=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/tpl/tpl.go | 15 +++++++++++++++ router/router.go | 9 +++++++-- router/system/sys_router.go | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 apis/tpl/tpl.go 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) }