var cookieParser = require('cookie-parser');
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
app.use(cookieParser(SecretKey));
app.use( bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
var redisURL = url.parse(process.env.REDISCLOUD_URL);
app.use(session({
store: new RedisStore({ url: redisURL.hostname , port: redisURL.port, client: redis }),
secret: SecretKey,
resave: true,
saveUninitialized: true,
key: 'sid',
cookie: {
secure: false,
httpOnly: false,
}
})
);
//this part below is actually later down in the code so the req variable does exist
if (req.session.language) {console.log(1);}
else {console.log(0)};
这似乎是正确的,当我在本地运行redis服务器时我的代码工作但我不明白为什么它没有连接到Heroku Redis Cloud。它应该与设置代码有关。任何帮助表示赞赏!谢谢!