Skip to content

Commit 928022b

Browse files
committed
add trust proxy option to express when in prod
1 parent a764991 commit 928022b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

apps/api/src/main.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function bootstrapNestApp() {
2222
await app.listen(PORT || 3000);
2323
}
2424

25-
export function configureNestApp(app: INestApplication): void {
25+
export function configureNestApp(app: NestExpressApplication): void {
2626
// Allow for base64 attachments
2727
app.use(json({ limit: '50mb' }));
2828

@@ -41,7 +41,7 @@ export function configureNestApp(app: INestApplication): void {
4141
app.use(passport.session());
4242
}
4343

44-
async function setupSwagger(app: INestApplication) {
44+
async function setupSwagger(app: NestExpressApplication) {
4545
const config = new DocumentBuilder()
4646
.setTitle('StockedUp API')
4747
.setDescription('StockedUp API documentation')
@@ -51,12 +51,20 @@ async function setupSwagger(app: INestApplication) {
5151
SwaggerModule.setup('api', app, document);
5252
}
5353

54-
async function setupSession(app: INestApplication) {
54+
async function setupSession(app: NestExpressApplication) {
5555
const redisStore = new RedisStore({
5656
client: redisClient,
5757
prefix: 'session:',
5858
});
5959

60+
const isProduction = Utils.isProduction();
61+
62+
if (isProduction) {
63+
// Allow for setting secure cookies via reverse proxy
64+
// Recommended deployment way is NGINX reverse proxy
65+
app.set('trust proxy', 1);
66+
}
67+
6068
app.use(
6169
session({
6270
store: redisStore,

0 commit comments

Comments
 (0)