0

Is it possible in http-proxy to do not forward requests to the server, but at once return a response with some error code, for example with 401 Unauthorized?
I need analyze request body and in some cases do not forward requests to the server.

is it possible to do at all?
Or http-proxy can only modify request and response, but request always should be forwarded to the server?

1 Answer 1

1

you can try doing it this way:

const server = http.createServer((req, res) => {
    if(/*your auth check*/){
        //return the 401 error
    }
    //auth check is passed, pass the request to the proxy
    proxy.web(req, res, { target: 'http://your.target' });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.