How to create another session in url based on nodejs?

Our site consists of two sections:

1. admin (content management)  
2. site

In the administrator section, the link url '/ admin' and the site '/' will be indicated.

Example: my site name is www.example.com, then the URL of the admin section is "www.example.com/admin", and the URL of the site is "www.example.com".

I want to create a session based on the url. The request from the admin section will have a different session than the request from the site section.

How can i do this?

+4
source share
1 answer

, , .

/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;

< > /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);

+1

Source: https://habr.com/ru/post/1570873/


All Articles