Skip to content

Commit

Permalink
test: Add visibility for CORS processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Anton committed Apr 16, 2024
1 parent 6084e61 commit a12688a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/api/src/config/cors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { INestApplication, Request } from '@nestjs/common';
import { INestApplication, Logger } from '@nestjs/common';
import { HttpRequestHeaderKeysEnum } from '../app/shared/framework/types';

export const corsOptionsDelegate: Parameters<INestApplication['enableCors']>[0] = function (req: Request, callback) {
Expand All @@ -25,7 +25,14 @@ export const corsOptionsDelegate: Parameters<INestApplication['enableCors']>[0]
process.env.NODE_ENV === 'dev' &&
host.includes(process.env.PR_PREVIEW_ROOT_URL);

Logger.verbose(`Should allow deploy preview? ${shouldDisableCorsForPreviewUrls ? 'Yes' : 'No'}.`, {
curEnv: process.env.NODE_ENV,
previewUrlRoot: process.env.PR_PREVIEW_ROOT_URL,
host,
});

if (shouldDisableCorsForPreviewUrls) {
Logger.verbose(`Allowing deploy previews.`);
corsOptions.origin.push('*');
}
}
Expand Down

0 comments on commit a12688a

Please sign in to comment.