Express doesn't set a cookie

后端 未结 10 1597
花落未央
花落未央 2020-12-14 01:45

I have problem with setting a cookies via express. I\'m using Este.js dev stack and I try to set a cookie in API auth /login route. Here is the cod

10条回答
  •  悲&欢浪女
    2020-12-14 02:14

    One of the main features is to set header correctly.

    For nginx:

    add-header Access-Control-Allow-Origin' 'domain.com';

    add_header 'Access-Control-Allow-Credentials' 'true';

    Add this to your web server.

    Then form cookie like this:

    "cookie": {
            "secure": true, 
            "path": "/", 
            "httpOnly": true, 
            "hostOnly": true, 
            "sameSite": false, 
            "domain" : "domain.com"
        }
    

    The best approach to get cookie from express is to use cookie-parser.

提交回复
热议问题