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

前端 未结 4 1970
予麋鹿
予麋鹿 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:42

    In my case setting "cookieDomainRewrite": "localhost", works. This allows the browser to setup correctly the cookies since the domain would match

    Below complete config for setupProxy.js in React:

    const {createProxyMiddleware} = require('http-proxy-middleware');
    
    module.exports = function (app) {
        app.use(
            '/api',
            createProxyMiddleware({
                target: 'http://localhost:8000',
                changeOrigin: true,
                cookieDomainRewrite: "localhost",
            })
        );
    };
    

提交回复
热议问题