j_q*_*lly 7 javascript api proxy webpack webpack-dev-server
我正在尝试使用动态查询参数代理我的请求,但似乎收到 404 错误或根本没有响应。这是我迄今为止尝试过的:
'/services/app/details.json?id=*': {
target: 'https://website.com/api/v1/potato/',
changeOrigin: true,
secure: true,
pathRewrite: {
'^/services/app/details.json?id=': '',
},
}
Run Code Online (Sandbox Code Playgroud)
我期待来自我的本地机器 ( /services/app/details.json?id=2189)的请求代理到https://website.com/api/v1/potato/2189但似乎id没有附加到目标请求并导致 404 错误。
我尝试使用该bypass方法自己附加 id,而没有给我任何响应对象。
'/services/app/details.json?id=*': {
target: 'https://website.com/api/v1/potato/',
changeOrigin: true,
secure: true,
pathRewrite: {
'^/services/app/details.json?id=': '',
},
bypass(req, res, proxyOptions) {
const id = (req.query.id ? req.query.id : '');
const API = Object.assign({}, proxyOptions, {
target: proxyOptions.target + id,
});
return API.target;
},
}
Run Code Online (Sandbox Code Playgroud)
有任何人对此有经验吗?
| 归档时间: |
|
| 查看次数: |
1795 次 |
| 最近记录: |