uniappH5 fly.js Golang 解决跨域问题

在做一个公众号商城,遇到了跨域问题。

后端用了beego框架

ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS") 
ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "Content-Type,Authorization") 
ctx.ResponseWriter.Header().Set("Access-Control-Max-Age", "1728000")
ctx.ResponseWriter.Header().Set("Access-Control-Allow-Credentials", "true")
ctx.ResponseWriter.Header().Set("content-type", "application/json") 

  

mainfest设置

    "h5":{
	"devServer": {
		"port": 9000,
		"disableHostCheck": true,
		"proxy" : {
                  "/" : {
                      "target" : "http://localhost:6601/",  //端口修改成你自己的
                      "changeOrigin" : true,
                      "secure" : false,
                      "pathRewrite" : {
                          "^/" : "/"
                      }
                  }
		},
		"https" : false 
	}
  },
    

用了fly请求,所以拦截中千万不要设置baseURL!!不要设置baseURL!!不要设置baseURL!!

原文地址:https://www.cnblogs.com/yewook/p/13049316.html