首页 > 解决方案 > Cookie 在 HttpHeaders 中可用,但在应用程序中不可用

问题描述

我的 Express 会话是 -

  secret: 'secret',
  resave: false,
  saveUninitialized: false,
  cookie:{
    maxAge:600000,
    httpOnly:false,
    secure:false,
    SameSite:"None"
  }
}))

CORS 详细信息是 -

// CORS enabled
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "http://localhost:4200, http://127.0.0.1:4200"); // update to match the domain you will make the request from
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  res.header("Access-Control-Allow-Credentials", true);
  next();
});
app.use(cors({
  origin:['http://localhost:4200','http://127.0.0.1:4200'],
  credentials:true
}))

我对角度的要求是 -

{
      observe:'body',
      withCredentials:true,
      headers:new HttpHeaders().append('Content-Type','application/json')
    }

我不确定为什么 cookie 在标头的 set-cookie 下可用,但在 Application.cookie 中不可用。正在从 localhost:4200 向 localhost:3000 发出请求。

标签: node.jsangularexpresssessioncookies

解决方案


推荐阅读