我有这样的代理配置:
proxy: {
"/api/smth": {
target: "http://api.example.com/",
secure: false,
changeOrigin: true,
},
}
现在我想将api调用/api/*/meta
重定向到本地文件%PROJ_ROOT%/meta/*.json
。
我该如何配置?
proxy: {
"/api/*/meta": {
selfHandleResponse: true,
bypass(req, resp) {
const id = req.url.match(/api\/([-\w]+)\/meta/)[1];
resp.header("Content-Type", "application/json");
fs.createReadStream(`./meta/${id}.json`).pipe(resp);
},
},
"/api/smth": {
target: "http://api.example.com/",
secure: false,
changeOrigin: true,
},
}