proxyserver
This commit is contained in:
@@ -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:], "/")
|
||||
|
||||
Reference in New Issue
Block a user