Our site have two section :
1. admin (content management)
2. site
Admin section will have url '/admin' and site section have url '/'.
Example : My site name is www.example.com, then admin section url is "www.example.com/admin" and site url is "www.example.com".
I want to create url based session means request from admin section will have different session than request from site section.
How can i do it?
Assuming you're using express, you can separate your routers for your routes and apply the session middleware to each router.
routes/index.js
var express = require('express'),
router = express.Router(),
session = require('express-session');
router.use(session({
secret: 'index route secret',
resave: false,
saveUninitialized: true
}));
module.exports = router;
routes/admin.js
var express = require('express'),
router = express.Router(),
session = require('express-session');
router.use(session({
secret: 'admin route secret',
resave: false,
saveUninitialized: true
}));
module.exports = router;
app.js
var express = require('express'),
app = express();
app.use('/', require('./routes/index'));
app.use('/admin', require('./routes/admin'));
app.listen(3000);
documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With