proxyserver

This commit is contained in:
eson
2023-10-09 14:41:57 +08:00
parent 12a6e95a11
commit 9fdc5b4dbf
10 changed files with 94 additions and 61 deletions

View File

@@ -91,23 +91,20 @@ func main() {
routes...))
}
Backends = append(Backends, NewBackend(mux,
fmt.Sprintf("http://%s:%d", "localhost", 9501),
"/api/v1/namespaces/kubernetes-dashboard"))
// 定义用于服务Vue dist文件夹的静态文件服务器
fs := http.FileServer(http.Dir(vueBuild))
indexHtmlPath := vueBuild + "/index.html"
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/api/") {
r.ParseMultipartForm(100 << 20)
// if err != nil {
// logx.Error(err)
// }
// 对/api开头的请求进行反向代理
proxy := httputil.NewSingleHostReverseProxy(apiURL)
proxy.ServeHTTP(w, r)
return
} else {
// 根据请求路径判断是服务静态文件或者是返回index.html
idx := strings.Index(r.URL.Path[1:], "/")