-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move redis to session middleware. * Rename appSession export to session. * Use Client's URL instead of port in cors.
- Loading branch information
Showing
7 changed files
with
27 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
PORT= | ||
CLIENT_PORT= | ||
CLIENT_URL= | ||
SESSION_SECRET= | ||
DB_NAME= | ||
DB_USER= | ||
DB_PASS= | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import corsInit from "cors"; | ||
|
||
export const cors = corsInit({ | ||
origin: `http://localhost:${process.env.CLIENT_PORT}`, | ||
origin: process.env.CLIENT_URL, | ||
credentials: true, | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
import { redisClient, RedisStore } from "./redis"; | ||
import connectRedis from "connect-redis"; | ||
import sessionInit from "express-session"; | ||
import redis from "redis"; | ||
|
||
import session from "express-session"; | ||
import { IS_PROD, SESSION_COOKIE_NAME } from "../utils/constants"; | ||
|
||
export const appSession = session({ | ||
name: "qid", | ||
export const RedisStore = connectRedis(sessionInit); | ||
export const redisClient = redis.createClient(); | ||
|
||
export const session = sessionInit({ | ||
name: SESSION_COOKIE_NAME, | ||
store: new RedisStore({ | ||
client: redisClient, | ||
disableTouch: true, | ||
disableTTL: true, | ||
}), | ||
saveUninitialized: false, | ||
cookie: { | ||
maxAge: 1000 * 60 * 60 * 24 * 365 * 10, | ||
httpOnly: true, | ||
secure: process.env.NODE_ENV === "production", | ||
secure: IS_PROD, | ||
sameSite: "lax", | ||
}, | ||
secret: "keyboard cat", | ||
saveUninitialized: false, | ||
secret: process.env.SESSION_SECRET as string, | ||
resave: false, | ||
}); |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const IS_PROD = process.env.NODE_ENV === "production"; | ||
export const SESSION_COOKIE_NAME = "session"; |