具体过程就不说,是搞这个的自然会动,只把关键代码贴出来。
beego和vue前后端分离开发,beego承载vue前端分离页面部署
// landv.cnblogs.com
//没有授权转载我的内容,再不加链接,呵呵
package main import (
_ "aa/routers"
"github.com/astaxie/beego/context"
"net/http"
"strings" "github.com/astaxie/beego"
) func main() {
ignoreStaticPath()
beego.Run()
} func ignoreStaticPath() {
//pattern 路由规则,可以根据一定的规则进行路由,如果你全匹配可以用"*"
// beego.InsertFilter("*",beego.BeforeRouter,TransparentStatic)
beego.InsertFilter("/",beego.BeforeRouter,TransparentStatic)
beego.InsertFilter("/*",beego.BeforeRouter,TransparentStatic)
} func TransparentStatic(ctx *context.Context) {
orpath := ctx.Request.URL.Path
beego.Debug("request url:",orpath)
//如果请求url还有api字段,说明指令应该取消静态资源路径重定向
if strings.Index(orpath,"api")>={
return
}
if strings.Index(orpath,"test")>={ return
}
http.ServeFile(ctx.ResponseWriter,ctx.Request,"static/lan/dist/"+ctx.Request.URL.Path)
}