-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added http exception filter and configured cors
- Loading branch information
1 parent
36312d5
commit 012a32d
Showing
2 changed files
with
37 additions
and
2 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,10 +1,30 @@ | ||
import { HttpException, HttpStatus } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
import { HttpExceptionFilter } from './modules/http'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule, { | ||
logger: ['error', 'warn', 'debug', 'verbose', 'log'], | ||
cors: true, | ||
}); | ||
|
||
app.useGlobalFilters(new HttpExceptionFilter()); | ||
|
||
const AllowedDomains = process.env.ALLOWED_DOMAINS.split(',') || []; | ||
|
||
app.enableCors({ | ||
origin: (origin, callback) => { | ||
if (AllowedDomains.includes(origin)) { | ||
callback(null, true); | ||
} else { | ||
callback( | ||
new HttpException('Not allowed by CORS', HttpStatus.BAD_GATEWAY), | ||
); | ||
} | ||
}, | ||
}); | ||
|
||
await app.listen(process.env.PORT || 3333); | ||
} | ||
bootstrap(); |
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