Cookie在localhost上运行良好,但在VPS上不起作用

时间:2017-10-05 12:17:50

标签: angularjs node.js cookies vps

我正在使用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,但它仍然不起作用。

1 个答案:

答案 0 :(得分:1)

我发现只需将WARNING in ./client/components/admin/includes/HeaderSideBar.jsx There are multiple modules with names that only differ in casing. This can lead to unexpected behavior when compiling on a filesystem with other case-semantic. Use equal casing. Compare these module identifiers: * /Users/developer/Desktop/Books/node_modules/babel-loader/lib/index.js!/Users/developer/Desktop/Books/client/components/admin/includes/HeaderSideBar.jsx Used by 1 module(s), i. e. /Users/developer/Desktop/Books/node_modules/babel-loader/lib/index.js!/Users/developer/Desktop/Books/client/components/admin/pages/AddANewBook.jsx * /Users/developer/Desktop/Books/node_modules/babel-loader/lib/index.js!/Users/developer/Desktop/Books/client/components/admin/includes/HeaderSidebar.jsx Used by 1 module(s), i. e. /Users/developer/Desktop/Books/node_modules/babel-loader/lib/index.js!/Users/developer/Desktop/Books/client/components/admin/index.jsx webpack: Compiled with warnings. 选项从domain更改为服务器的IP