章節連結
pathRewrite 在 http-proxy-middleware 這個套件,除了可以用物件 key-value 來覆寫路由路徑,也可給一個 Function 來自訂。這邊筆記下自定義 pathRewrite 的方式。
內容
這回的情境是絕大多數都是導向 a 位置,但少數幾隻要導向 b 位置。那麼可以這樣寫:
1 2 3 4 5 6 7 8 9 |
{ pathRewrite: (path, req) => { if (req.path.includes('language_request')) { return path.replace(req.path, '/language_request') } return path } } |