Mehmet
Mehmet

Reputation: 1

app[web.1]: Warning: connect.session() MemoryStore is not .Heroku is not working

pls help me,heroku application error, this is heroku view log:

2020-03-25T00:13:32.809756+00:00 app[web.1]: Warning: connect.session() MemoryStore is not 2020-03-25T00:13:32.809769+00:00 app[web.1]: designed for a production environment, as it will leak 2020-03-25T00:13:32.809770+00:00 app[web.1]: memory, and will not scale past a single process. 2020-03-25T00:13:32.821438+00:00 app[web.1]: Server started on8000 2020-03-25T00:13:32.958702+00:00 app[web.1]: veritabanına bağlandı

Upvotes: 0

Views: 1196

Answers (2)

Namiq Muhammedi
Namiq Muhammedi

Reputation: 9

First setting the variable on the host panel:

name: SESSION_SECRET, variable: "yoursKey"

Next stpe is adding below link in the app.js file:

const session = require('express-session')
const SequelizeStore = require("connect-session-sequelize")(session.Store);

Setting the session and session stor:

app.set('trust proxy', 1); // trust first proxy
app.use(cookieParser());

app.use(session({
    secret: process.env.SESSION_SECRET,
    resave: false,
    saveUninitialized: true,
    cookie: {
        secure: true,
        maxAge: 1000 * 60 * 60 * 1 // 1 hours
    },
    storage: new SequelizeStore({
    db: sequelize
    })
}))

For more information please look this tutorial

Upvotes: 0

John Galt
John Galt

Reputation: 50

You've got a few options here. 1st: You created a user session using express-session but forgot to add the session secret to the vars in heroku config vars Ex:

app.use(
session({
  secret: process.env.SESSION_SECRET,
  resave: false,
  saveUninitialized: true,

Using process.env.SESSION_SECRET and not adding the secret to heroku vars will give you this error (that was my case)

2nd: You didn't specify where to store the session. You should add a storing system that store sessions into your database. This helps your app to manage sessions.

For example, in mongodb you can use connect-mongo, you should found a store package and for other databases.

Ex:

const session = require('express-session');
const MongoStore = require('connect-mongo')(session);

app.use(session({
    secret: 'foo',
    store: new MongoStore(options)
}));

By doing this you're storing the session in mongo.

3rd: Last option if all fails, i do not recommend tho, is storing the cookis client-side instead of server-side. To do this you must replace express-session (if you're using it) with cookie-session.

Ex:

npm i cookie-session
var session = require('cookie-session');

Then writing the app.use as normally

Upvotes: 1

Related Questions