Merge pull request #73 from lanyulei/dev

feat: 兼容前后端不分离的情况。
This commit is contained in:
lanyulei 2020-10-13 00:17:04 +08:00 committed by GitHub
commit fd74df8289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
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)

View File

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