Created
September 6, 2021 23:53
-
-
Save MohammedALREAI/28074aa06264d3a95ecd5888a0bfe7c5 to your computer and use it in GitHub Desktop.
Redis simple used
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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