Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Session Zappa中的会话(node.js)_Session_Node.js_Express_Zappa - Fatal编程技术网

Session Zappa中的会话(node.js)

Session Zappa中的会话(node.js),session,node.js,express,zappa,Session,Node.js,Express,Zappa,使用Zappa启用会话的正确方式是什么 Zappa速成班意味着我只需要@使用'cookies',session:{secret:'asdf'},但这不是导出@请求。session--我缺少什么吗?调用下面的console.log会导致打印未定义的 require('zappa') '0.0.0.0', '8080', -> @use 'bodyParser', 'methodOverride', @app.router, 'static',

使用Zappa启用会话的正确方式是什么

Zappa速成班意味着我只需要
@使用'cookies',session:{secret:'asdf'}
,但这不是导出
@请求。session
--我缺少什么吗?调用下面的console.log会导致打印
未定义的

require('zappa') '0.0.0.0', '8080', ->

  @use 'bodyParser',
       'methodOverride',
       @app.router,
       'static',
       'cookies',
       'cookieParser',
       session: {secret: '5465hfgh3t4grf'}

  @configure
    development: => @use errorHandler: {dumpExceptions: on}
    production: => @use 'errorHandler'

  @get '/': -> 
    console.log( @request.session )
    @render 'index.eco', {loginkey: @request.sessionID}

您需要在路由上方安装
会话
中间件:

require('zappa') '0.0.0.0', '8080', ->

  @use 'bodyParser',
       'methodOverride',
       'cookies',
       'cookieParser',
       session: {secret: '5465hfgh3t4grf'},
       @app.router,
       'static'

  @configure
    development: => @use errorHandler: {dumpExceptions: on}
    production: => @use 'errorHandler'

  @get '/': -> 
    console.log( @request.session )
    @render 'index.eco', {loginkey: @request.sessionID}
否则,在路由执行之前,您将无法对请求执行
会话
,也就是说

更新:还请注意,与zappa中
请求
上的其他属性一样,
会话
被复制到
,因此您可以直接访问
@session
。在
请求上也没有
会话id
,但有
@session.id
,您可能需要以下路径:

@get '/': -> 
  console.log( @session )
  @render 'index.eco', {loginkey: @session.id}