我正在嘗試使用Golang和gin為我的api和前端編寫代理。如果請求轉(zhuǎn)到除“/api”之外的任何內(nèi)容,我想代理到svelte服務(wù)器。如果去“/api/something”,我想在杜松子酒中處理它。目前我的代碼是這樣的。func proxy(c *gin.Context) { remote, err := url.Parse("http://localhost:3000") if err != nil { panic(err) } proxy := httputil.NewSingleHostReverseProxy(remote) proxy.Director = func(req *http.Request) { req.Header = c.Request.Header req.Host = remote.Host req.URL.Scheme = remote.Scheme req.URL.Host = remote.Host req.URL.Path = c.Param("proxyPath") } proxy.ServeHTTP(c.Writer, c.Request)}func main() { r := gin.Default() r.Any("/*proxyPath", proxy) r.Run(":8080")}現(xiàn)在,如果我去,我看到我的苗條的應(yīng)用程序。但是,如果想要添加任何其他路由,我會收到一個錯誤http://localhost:8080panic: catch-all conflicts with existing handle for the path segment root in path '/*proxyPath'
- 1 回答
- 0 關(guān)注
- 150 瀏覽
添加回答
舉報
0/150
提交
取消