Shared Sessions between Node Apps?

后端 未结 2 725
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 00:19

I currently have two separate node apps running on two different ports but share the same backend data store. I need to share users sessions between the two apps so that wh

2条回答
  •  佛祖请我去吃肉
    2021-01-05 00:30

    Maybe a bit outdated, but at this time, Express-session can recognise domain option for cookie. According to source:

    function session(options){
      var options = options || {}
      //  name - previously "options.key"
        , name = options.name || options.key || 'connect.sid'
        , store = options.store || new MemoryStore
        , cookie = options.cookie || {}
          ...
    

    And this is for setting cookie:

    var Cookie = module.exports = function Cookie(options) {
      this.path = '/';
      this.maxAge = null;
      this.httpOnly = true;
      if (options) merge(this, options);
      ...
    

    So, something like this will work for current 1.10.1 master:

    secret: "my secret",
        cookie: {
            domain: "mydomain.com",
    

提交回复
热议问题