NestJS 수정2..
This commit is contained in:
parent
c354f2f804
commit
4084b8d2cf
27
src/main.ts
27
src/main.ts
@ -1,12 +1,37 @@
|
||||
//참고 : 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('listening on port 3000')
|
||||
console.log(
|
||||
'[CORS-enabled->npm install -g webpack webpack-cli] web server listening on port 3000'
|
||||
)
|
||||
})
|
||||
}
|
||||
bootstrap()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user