Skip to content

Commit

Permalink
Merge pull request #5420 from novuhq/deploy-preview-cors
Browse files Browse the repository at this point in the history
test: Add visibility for CORS processing
  • Loading branch information
Cliftonz authored Apr 16, 2024
2 parents 6084e61 + a12688a commit 49bb545
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 49bb545

Please sign in to comment.