nacos config

This commit is contained in:
eson
2023-09-22 10:37:34 +08:00
parent c4b4b72947
commit 15f589c09d
3 changed files with 21 additions and 1 deletions

View File

@@ -97,6 +97,7 @@ func main() {
indexHtmlPath := vueBuild + "/index.html"
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/api/") {
err := r.ParseMultipartForm(100 << 20)
if err != nil {
logx.Error(err)
@@ -104,6 +105,17 @@ func main() {
// 对/api开头的请求进行反向代理
proxy := httputil.NewSingleHostReverseProxy(apiURL)
proxy.ErrorHandler = func(res http.ResponseWriter, req *http.Request, err error) {
if err != nil {
// 在发生错误时进行处理
logx.Error(err)
res.WriteHeader(http.StatusNotFound) // 返回404状态码
_, err := res.Write([]byte(err.Error()))
if err != nil {
logx.Error(err)
}
}
}
proxy.ServeHTTP(w, r)
return