大家好,我有一个Angular 4应用程序在本地计算机上调用Express API,这些应用程序在不同的端口(4200和3000)运行。在我配置的Express应用程序中:
app.use((req, res, next) => {
console.log(req.headers.origin);
res.header('Access-Control-Allow-Origin', req.headers.origin);
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
if ('OPTIONS' == req.method) {
res.sendStatus(200);
} else {
next();
}
});
和我的cookie配置:
app.use(session({
resave: true,
saveUninitialized: true,
secret: process.env.SESSION_SECRET,
cookie: {
httpOnly: true,
expires: cookieExpirationDate // use expires instead of maxAge
}
}));
在Angular 4中,使用
调用请求this.http.post(environment.services + '/login', user, {withCredentials: true});
一切都在localhost中运行。但随后这些应用程序被部署到不同的heroku应用程序。会话在第一个呼叫中设置,但在其他呼叫中不再存在。我想念一下吗?
答案 0 :(得分:0)