新增自定义的 Cors
This commit is contained in:
@@ -30,7 +30,7 @@ func SetCors(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func main() {
|
||||
rootDir := "../server" // Change this to your root directory
|
||||
vueBuild := "/home/ldm/workdir/fusenpack-vue-created"
|
||||
vueBuild := "/home/eson/workspace/fusenpack-vue-created"
|
||||
apiURL, err := url.Parse("http://localhost:9900")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -130,7 +130,7 @@ func NewBackend(mux *http.ServeMux, httpAddress string, muxPaths ...string) *Bac
|
||||
return
|
||||
}
|
||||
|
||||
hasBridge := strings.Contains(r.Header.Get("Access-Control-Request-Headers"), "bridge")
|
||||
// hasBridge := strings.Contains(r.Header.Get("Access-Control-Request-Headers"), "bridge")
|
||||
|
||||
// 解析目标URL时已经包含了查询参数
|
||||
targetURL.RawQuery = r.URL.RawQuery
|
||||
@@ -166,9 +166,9 @@ func NewBackend(mux *http.ServeMux, httpAddress string, muxPaths ...string) *Bac
|
||||
}
|
||||
}
|
||||
|
||||
if hasBridge {
|
||||
w.Header().Add("Access-Control-Allow-Headers", "Bridge")
|
||||
}
|
||||
// if hasBridge {
|
||||
// w.Header().Add("Access-Control-Allow-Headers", "Bridge")
|
||||
// }
|
||||
|
||||
// 转发目标服务器的响应状态码和主体
|
||||
w.WriteHeader(resp.StatusCode)
|
||||
@@ -177,8 +177,8 @@ func NewBackend(mux *http.ServeMux, httpAddress string, muxPaths ...string) *Bac
|
||||
http.Error(w, "Error copying proxy response", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for _, muxPath := range muxPaths {
|
||||
mux.HandleFunc(muxPath, handleRequest)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user