feat: 兼容前后端不分离的情况。

This commit is contained in:
Mr. Lan 2020-10-13 00:14:14 +08:00
parent db8b5faf0e
commit 65b8090ad0
3 changed files with 23 additions and 3 deletions

15
apis/tpl/tpl.go Normal file
View File

@ -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{})
}

View File

@ -1,6 +1,7 @@
package router package router
import ( import (
"ferry/apis/tpl"
"ferry/pkg/jwtauth" "ferry/pkg/jwtauth"
"ferry/router/dashboard" "ferry/router/dashboard"
"ferry/router/process" "ferry/router/process"
@ -19,7 +20,7 @@ func InitSysRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) *gin
systemRouter.SysBaseRouter(g) systemRouter.SysBaseRouter(g)
// 静态文件 // 静态文件
sysStaticFileRouter(g) sysStaticFileRouter(g, r)
// swagger注意生产环境可以注释掉 // swagger注意生产环境可以注释掉
sysSwaggerRouter(g) sysSwaggerRouter(g)
@ -33,8 +34,9 @@ func InitSysRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) *gin
return g return g
} }
func sysStaticFileRouter(r *gin.RouterGroup) { func sysStaticFileRouter(r *gin.RouterGroup, g *gin.Engine) {
r.Static("/static", "./static") r.Static("/static", "./static")
g.LoadHTMLGlob("template/web/index.html")
} }
func sysSwaggerRouter(r *gin.RouterGroup) { func sysSwaggerRouter(r *gin.RouterGroup) {
@ -48,6 +50,9 @@ func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwtauth.GinJWTMi
v1 := r.Group("/api/v1") v1 := r.Group("/api/v1")
// 兼容前后端不分离的情
r.GET("/", tpl.Tpl)
// 首页 // 首页
dashboard.RegisterDashboardRouter(v1, authMiddleware) dashboard.RegisterDashboardRouter(v1, authMiddleware)

View File

@ -14,7 +14,7 @@ import (
) )
func SysBaseRouter(r *gin.RouterGroup) { func SysBaseRouter(r *gin.RouterGroup) {
r.GET("/", system.HelloWorld) //r.GET("/", system.HelloWorld)
r.GET("/info", handler.Ping) r.GET("/info", handler.Ping)
} }