【发布时间】:2018-03-17 01:29:17
【问题描述】:
我正在使用 nodejs 和 angularjs 1.6.4。在 localhost 上一切正常,但是当我通过 Github 将代码推送到 Digital Ocean droplet 时,cookie 不起作用。我保存到 cookie 的所有内容都不会出现在 Cookie 存储中。为什么会这样?
更新
当我在 VPS 上进入登录页面时出现警告:"This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar"
下面是相关代码:
$scope.login = function () {
UserService.login($scope.user).then(function (result) {
if (result.data.success) {
$rootScope.userLogin = result.data.data.name;
//------------------
var day = new Date();
day.setDate(day.getDay() + 30);
var options = {
domain: "localhost",
httpOnly: true,
expires: day
};
// cookie does not work, nothing in Cookie Storage
// but it works perfectly on localhost
$cookies.put('token', result.data.data.token, options);
$cookies.put('name', result.data.data.name, options);
// the session storage work greatly
$sessionStorage.user = 'heheeheh';
flash.success = result.data.message;
$state.go('home');
} else {
flash.error = result.data.message;
}
});
}
更新:
我在亚马逊 ec2 上创建了另一个 VPS,但它仍然无法正常工作。
【问题讨论】:
-
控制台中是否显示任何错误或警告?
-
另外,请贴出相关代码。
标签: angularjs node.js cookies vps