Expressjs secure session cookie

后端 未结 2 802
梦毁少年i
梦毁少年i 2021-02-07 11:55

I cant seem to find a way to set a secure cookie in expressjs framework. Is there an option to do this somewhere?

2条回答
  •  耶瑟儿~
    2021-02-07 12:08

    If you are behind a proxy, you also have to ensure it is sending the X-Forwarded-Proto header and that you set the proxy option:

    app.use(express.session({
      proxy: true,
      secret: 'test',
      cookie: {
        secure: true
      }            
    }));
    

    Alternatively, you can tell Express to trust the proxy globally:

    app.set('trust proxy', 1)
    

提交回复
热议问题