-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
44 changed files
with
942 additions
and
967 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
Large diffs are not rendered by default.
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
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,13 +1,5 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class UnauthorizedError { | ||
@ApiProperty({ | ||
example: ['No token', 'Invalid token', 'Token expired'], | ||
}) | ||
message: string[]; | ||
|
||
@ApiProperty({ | ||
example: 'Unauthorized', | ||
}) | ||
error: 'Unauthorized'; | ||
} |
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,53 +1,16 @@ | ||
import 'dotenv/config'; | ||
import { NestFactory, Reflector } from '@nestjs/core'; | ||
import { ValidationPipe } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
import { ClassSerializerInterceptor, ValidationPipe } from '@nestjs/common'; | ||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; | ||
import * as cookieParser from 'cookie-parser'; | ||
import { BaseExceptionFilter } from 'src/core/filters/base-exception-filter'; | ||
import { writeFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
// set CORS | ||
app.useGlobalPipes(new ValidationPipe()); | ||
app.enableCors({ | ||
origin: true, | ||
origin: process.env.CORS_ORIGIN, | ||
credentials: true, | ||
exposedHeaders: ['Authorization'], | ||
}); | ||
// set swagger module | ||
const config = new DocumentBuilder() | ||
.setTitle('Meta Test API') | ||
.setDescription('The Meta Test API') | ||
.setVersion('1.0.0') | ||
.addBearerAuth() | ||
.build(); | ||
const document = SwaggerModule.createDocument(app, config); | ||
const swaggerJson = JSON.stringify(document, null, 2); | ||
writeFileSync(join(process.cwd(), 'swagger-spec.json'), swaggerJson); | ||
SwaggerModule.setup('api', app, document); | ||
|
||
app.useGlobalPipes( | ||
new ValidationPipe({ | ||
transform: true, | ||
}), | ||
); | ||
|
||
app.useGlobalFilters(new BaseExceptionFilter()); | ||
|
||
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector))); | ||
app.use(cookieParser()); | ||
// set port | ||
const port = | ||
process.env.NODE_ENV === 'dev' | ||
? 8000 | ||
: process.env.NODE_ENV === 'production' | ||
? 8080 | ||
: 3000; | ||
|
||
console.log('server start at', port); | ||
|
||
const port = process.env.PORT || 3000; | ||
await app.listen(port); | ||
} | ||
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
Oops, something went wrong.