Skip to content

Instantly share code, notes, and snippets.

@MohammedALREAI
Created September 6, 2021 23:53
Show Gist options
  • Select an option

  • Save MohammedALREAI/28074aa06264d3a95ecd5888a0bfe7c5 to your computer and use it in GitHub Desktop.

Select an option

Save MohammedALREAI/28074aa06264d3a95ecd5888a0bfe7c5 to your computer and use it in GitHub Desktop.
Redis simple used
const RedisStore = connectRedis(session);
const redis = new Redis(process.env.REDIS_URL);
app.set("trust proxy", 1);
app.use(
cors({
origin: process.env.CORS_ORIGIN,
credentials: true,
})
);
app.use(
session({
name: COOKIE_NAME,
store: new RedisStore({
client: redis,
disableTouch: true,
}),
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 365 * 10, // 10 years
httpOnly: true,
sameSite: "lax", // csrf
secure: __prod__, // cookie only works in https
domain: __prod__ ? ".codeponder.com" : undefined,
},
saveUninitialized: false,
secret: process.env.SESSION_SECRET,
resave: false,
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment