2017-06-07 78 views
0

http-proxy可能不會將請求轉發到服務器,但是會立即返回帶有一些錯誤代碼的響應,例如401未授權?
我需要分析請求正文,並且在某些情況下不會將請求轉發到服務器。如何從http-proxy發送HTTP錯誤?

有沒有可能做?
或http代理只能修改請求和響應,但請求總是應該被轉發到服務器?

回答

1

你可以嘗試做這種方式:

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