Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to forwarding a request when the proxy not found . #1654

Open
gapkukb opened this issue Dec 4, 2023 · 1 comment
Open

How to forwarding a request when the proxy not found . #1654

gapkukb opened this issue Dec 4, 2023 · 1 comment

Comments

@gapkukb
Copy link

gapkukb commented Dec 4, 2023

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)
          }
        })
     }
   }
}
@gapkukb
Copy link
Author

gapkukb commented Dec 4, 2023

proxy.web can correct return the response when using "get" method,
but no response if using "post" method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant