【问题标题】:Node.js -TypeError : Object 1800000 has no method 'toUTCString'Node.js -TypeError:对象 1800000 没有方法“toUTCString”
【发布时间】:2015-12-24 16:51:16
【问题描述】:

我在我的 Node.js 应用程序中使用会话管理。默认快速会话可用于 Express MVC 应用程序。 在 app.js 文件中,我包含了我的 cookie 和会话过期时间。

app.use(session({
secret: 'ssshhhhh',
saveUninitialized: true,
resave: true,  
cookie:{maxAge:new Date(Date.now() + 1800000),expires:1800000},rolling:true})
);

但是当我执行我的代码时,它会抛出 ans Error Called TypeError: Object 1800000 has no method 'toUTCString' 请为此提供任何可行的解决方案。

【问题讨论】:

    标签: node.js session express cookies


    【解决方案1】:

    maxAge 应该是一个相对量(X 毫秒后),而expires 应该是一个绝对时间戳(在这个日期和时间)。你对两者都做了完全相反的事情。

    换句话说,试试这个:

    cookie : {
      maxAge  : 1800000,
      expires : new Date(Date.now() + 1800000),
      rolling : true
    }
    

    (虽然我不确定expires 是否是express-session 的有效选项)

    【讨论】:

    • 我试过了,但是在这样做之后,会话过期时间变为 - 负数。
    • 当网站在服务器上时,基本上会发生这种情况。
    • @arjunkori 你确定服务器和客户端的系统时间都是最新的吗?
    猜你喜欢
    • 2013-05-11
    • 2012-11-13
    • 1970-01-01
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    相关资源
    最近更新 更多