前端使用proxy穿透后查看真实请求地址方法
1、在vite.config.ts中的server配置
proxy: {
[env.VITE_APP_BASE_API]: {
changeOrigin: true,
target: env.VITE_APP_TARGET_BASE_API,
bypass(req, res, options) {
// 真实服务地址X-Req-Proxyurl
res.setHeader("X-Req-Proxyurl", options.target as string);
},
configure: (proxy, options) => {
// 配置后请求的真实接口地址在请求头x-real-url中
proxy.on("proxyRes", (proxyRes, req) => {
proxyRes.headers["x-real-url"] =
new URL(req.url || "", options.target as string)?.href || "";
});
},
},
},