怎么用node.js的session保存用户在前后台的登录信息
发布于 2年前 作者 zjshop 5859 次浏览

我现在监听两个端口分别用着前后台登录![enter image description here][1]

[1]: /upload/50cbf5fb637ffa41556d22f2/1355549518256_%E6%9C%AA%E5%91%BD%E5%90%8D.jpg 为什么我在前台登陆后去在后台也登录 然后前台又必须重新登录才行 前后台保存的session名字也不一样

5 回复

补充问题 app如下:

/**

  • Module dependencies. */

var express = require(‘express’) , http = require(‘http’) , path = require(‘path’) , flash = require(‘connect-flash’) , restRoute = require(‘./routes/rest-route’) , webRoute = require(‘./routes/web-route’) , adminRoute = require(‘./routes/admin-route’);

var app = express(); var adminapp = express();

app.configure(function(){ app.set('port’, process.env.PORT || 3000); app.set('views’, __dirname + ‘/views’); app.set('view engine’, ‘ejs’); app.use(express.favicon()); app.use(express.logger(‘dev’)); app.use(express.bodyParser({keepExtensions: true, uploadDir: ‘/uploads’ })); app.use(express.methodOverride()); app.use(flash()); app.use(express.cookieParser(‘your secret here’)); app.use(express.session({secret: "wind"})); app.use(app.router); app.use(express.static(path.join(__dirname, ‘assets’))); app.use(express.static(path.join(__dirname, ‘uploads’))); app.use(express.limit(‘3mb’)); });

app.configure('development’, function(){ app.use(express.errorHandler()); });

adminapp.configure(function(){ adminapp.set('port’, process.env.PORT || 3001); adminapp.set('views’, __dirname + ‘/views/admin’); adminapp.set('view engine’, ‘ejs’); adminapp.use(express.favicon()); adminapp.use(express.logger(‘dev’)); adminapp.use(express.bodyParser({keepExtensions: true, uploadDir: ‘/uploads’ })); adminapp.use(express.methodOverride()); adminapp.use(flash()); adminapp.use(express.cookieParser(‘your secret here’)); adminapp.use(express.session({secret: "wind"})); adminapp.use(adminapp.router); adminapp.use(express.static(path.join(__dirname, ‘assets’))); adminapp.use(express.static(path.join(__dirname, ‘uploads’))); adminapp.use(express.limit(‘3mb’)); });

adminapp.configure('development’, function(){ adminapp.use(express.errorHandler()); });

//web routers map webRoute.mapRoutes(app);

//admin routers map adminRoute.mapRoutes(adminapp);

//app.listen(3000); http.createServer(app).listen(3000); console.log(‘Express app started on port 3000’);

//adminapp.listen(3001); http.createServer(adminapp).listen(3001); console.log(‘Express app started on port 3001’);

很简单,一个用127.0.0.1登陆,另一个用局域网ip登陆,类似192.168.1.100这种。

不是一个连接,自然就不是一个session

如果是同一个连接呢,分前后台,分别存储注册用户和系统管理员的session,是否需要新建一个session呢,又如何控制不同的过期时间呢?

有必要搞两个不同的端口吗

回到顶部