node-http-proxy
node-http-proxy copied to clipboard
How to forwarding a request when the proxy not found .
trafficstars
Hi everyone.
I am using vite+vue in my project.
As I expect , I want implement a proxy on the vite to forwarding my local mock data when the backend api not implement(404), This is useful because the backend api is not always in sync with the frontend.
There is my code , but cannot get the response, thanks for everyone's help.
proxy:{
'/api':{
target:'http://www.example.com',
selfHandleResponse:true,
configure:proxy=>{
proxy.on('proxyRes',(proxyRes,req,res)=>{
if(proxyRes.statusCode===404){
// how to do here?
proxy.web(req,res,{target:'http://www.newExample.com'})
}else{
proxyRes.pipe(res)
}
})
}
}
}