Good day guys here is my code :
JavaScript
x
16
16
1
var express = require('express');
2
var session = require('express-session');
3
4
var app = express();
5
app.set('trust proxy', 1);
6
7
app.use(session({
8
secret: 'secret',
9
saveUninitialized: true,
10
resave: false,
11
maxAge: 1000 * 60 * 15,
12
cookie:{
13
secure: true
14
}
15
}));
16
this code always returns on my log a :
Warning: connect.session() MemoryStore is not designed for a production environment, as it will leak memory, and will not scale past a single process.
i tried googling about it but i don’t seems to understand some tutorials . Sorry for my bad english.
Advertisement
Answer
I hope this would help to someone who’s struggling the same problem as mine . Just dug it by myself .
JavaScript
1
21
21
1
//-momery unleaked---------
2
app.set('trust proxy', 1);
3
4
app.use(session({
5
cookie:{
6
secure: true,
7
maxAge:60000
8
},
9
store: new RedisStore(),
10
secret: 'secret',
11
saveUninitialized: true,
12
resave: false
13
}));
14
15
app.use(function(req,res,next){
16
if(!req.session){
17
return next(new Error('Oh no')) //handle error
18
}
19
next() //otherwise continue
20
});
21