不废话,直接上代码:
package main
import (
"net/http"
"path"
"github.com/gin-gonic/gin"
)
var (
vueAssetsRoutePath = "/opt/nginx/dist" // 前端编译出来的 dist 所在路径
)
func setRoute(g *gin.Engine) {
// 前端资源 url
g.StaticFile("/", path.Join(vueAssetsRoutePath, "index.html")) // 指定资源文件 url. 127.0.0.1/ 这种
g.StaticFile("/favicon.ico", path.Join(vueAssetsRoutePath, "favicon.ico")) // 127.0.0.1/favicon.ico
g.StaticFile("/_app.config.js", path.Join(vueAssetsRoutePath, "_app.config.js"))
g.StaticFS("/assets", http.Dir(path.Join(vueAssetsRoutePath, "assets"))) // 以 assets 为前缀的 url
g.StaticFS("/resource", http.Dir(path.Join(vueAssetsRoutePath, "resource"))) // 比如 127.0.0.1/resource/aa.js
// data 数据源 url
rg := g.Group("/api")
{
rg.POST("/login", login)
rg.GET("/logout", logout)
rg.POST("/register", register)
rg.GET("/downfile", downloadFileService)
dataRout := rg.Group("/app")
{
dataRout.GET("/userinfo", getUserInfo)
dataRout.POST("/transform", fileTransform)
}
}
// g.StaticFS("assets", http.Dir("视频地址"))// 直接播放视频
g.GET("/health", health)
}
网友评论