第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Golang gin proxy 來處理 svelte 前端和 Golang api

Golang gin proxy 來處理 svelte 前端和 Golang api

Go
繁花不似錦 2022-09-05 10:25:59
我正在嘗試使用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 回答

?
米琪卡哇伊

TA貢獻1998條經(jīng)驗 獲得超6個贊

您可以在 r.NoRoute 中 mv proxy funcr.NoRoute(proxy)



查看完整回答
反對 回復 2022-09-05
  • 1 回答
  • 0 關(guān)注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號