Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

引入radis错误!!! #185

Open
eugeneCN opened this issue Oct 17, 2017 · 4 comments
Open

引入radis错误!!! #185

eugeneCN opened this issue Oct 17, 2017 · 4 comments

Comments

@eugeneCN
Copy link

eugeneCN commented Oct 17, 2017

该代码在 yog/conf/plugins/session.js

var session = require('express-session');
var RedisStore = require('connect-redis')(session);

module.exports.session = {
  name: 'idKey',
  secret: 'yog',
  store: new RedisStore({
    host: "127.0.0.1",
    port: 8888,
    prefix: "NGM::",
    secret: "redis"
  }),
  resave: false,
  saveUninitialized: false,
  cookie: {
    maxAge: 1000 * 60 * 60
  }
};

但是控制台会报错。。

/Users/用户名/Desktop/YOG2/yog/node_modules/[email protected]@yog2-kernel/lib/loader.js:90
        debuglog('load plugin [%s] with conf %s', name, JSON.stringify(conf));
                                                             ^

TypeError: Converting circular structure to JSON

如何解决,是因为我引入的方式不对吗?求答案啊~~ @zhiqiang21

@zhiqiang21
Copy link

你可以看下这个关于安装和配置中间件的文档。http://fex.baidu.com/yog2/docs/features/middleware.html#中间件管理

还有就是你的问题,我认为是你这个session.js放置的目录不对。如果是针对某个app的配置,可以放到app的server目录下。

@eugeneCN
Copy link
Author

eugeneCN commented Oct 18, 2017

放在server是不起作用的,而且插件是通过 yog2 plugin install session 来安装的,安装后会在yog/conf/plugins目录下生成session.js。
生成的文件代码:

module.exports.session = {
    secret: 'yog',
    resave: false,
    saveUninitialized: true
};

module.exports.cookieParser = {
    secret: 'yog'
};

我集成了radis,然后出现了以上描述的问题。

@eugeneCN
Copy link
Author

解决了,我是这么干的。

在session插件里稍微做下修改。

var session = require('express-session');
var redisStrore = require('connect-redis')(session);

module.exports.session = function (app, conf) {
  Object.assign(conf, { store: new redisStrore(conf.redis) })
  return function () {
    app.use(session(conf))
  };
};

对外抛出的session

module.exports.session = {
  secret: 'yog',
  resave: false,
  saveUninitialized: false,
  cookie: {
    cookie: 1000 * 60
  },
  redis: {
    host: '127.0.0.1',
    port: '6379',
    secret: 'yog2'
  }
};

好像只有这种方式才行。

redis存储的sesstion

image

@zhiqiang21
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants