http-proxy-middleware, how to copy all/cookie headers

前端 未结 4 1975
予麋鹿
予麋鹿 2021-02-04 22:19

I am using lite server by John Papa with HTTP proxy middleware by chimurai as a dev server. the problem is with my session cookie, I cannot persist the session cookie that comes

4条回答
  •  借酒劲吻你
    2021-02-04 22:25

    try it:

    var cookie;
    function relayRequestHeaders(proxyReq, req) {
      if (cookie) {
        proxyReq.setHeader('cookie', cookie);
      }
    };
    
    function relayResponseHeaders(proxyRes, req, res) {
      var proxyCookie = proxyRes.headers["set-cookie"];
      if (proxyCookie) {
        cookie = proxyCookie;
      }
    };
    

    It's working with lite-server

提交回复
热议问题