Volodymyr Bezuglyy
Volodymyr Bezuglyy

Reputation: 16815

How to send HTTP error from http-proxy?

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?

Upvotes: 0

Views: 597

Answers (1)

Sasha Pomirkovany
Sasha Pomirkovany

Reputation: 542

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' });
});

Upvotes: 1

Related Questions