38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
//참고 : https://wikidocs.net/book/7059
|
|
|
|
import { HttpException, HttpStatus } from '@nestjs/common'
|
|
import { NestFactory } from '@nestjs/core'
|
|
import { AppModule } from './app.module'
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule)
|
|
//Enable All CORS Requests : https://docs.nestjs.com/security/cors
|
|
app.enableCors({
|
|
origin: (origin, callback) => {
|
|
//origin URL이 허용된 경우 또는 orgin자체가 없는 경우(postman tool) 통과
|
|
if (process.env.CORS_ALLOW_ORIGINS.indexOf(origin) !== -1 || !origin) {
|
|
console.log('Allowed Origin URL: ' + origin)
|
|
callback(null, true)
|
|
} else {
|
|
callback(
|
|
new HttpException(
|
|
{
|
|
status: HttpStatus.FORBIDDEN,
|
|
error: origin + '에서는 접근이 허용되지 않습니다.'
|
|
},
|
|
HttpStatus.FORBIDDEN
|
|
)
|
|
)
|
|
}
|
|
},
|
|
methods: process.env.CORS_ALLOW_METHOD,
|
|
credentials: true
|
|
})
|
|
await app.listen(3000, function () {
|
|
console.log(
|
|
'[CORS-enabled->npm install -g webpack webpack-cli] web server listening on port 3000'
|
|
)
|
|
})
|
|
}
|
|
bootstrap()
|