//참고 : https://wikidocs.net/book/7059 import { NestFactory } from '@nestjs/core' import { env } from 'process' import { AppModule } from './app.module' var cors = require('cors') async function bootstrap() { const app = await NestFactory.create(AppModule) //Enable All CORS Requests : https://github.com/expressjs/cors#enable-cors-for-a-single-route var corsOptions = function (req, callback) { const origin = req.header('Origin') var corsOptions if (env.CORS_ALLOW_LIST.indexOf(origin) !== -1) { corsOptions = { origin: true } // reflect (enable) the requested origin in the CORS response console.log('Allowed Origin URL: ' + origin) } else { corsOptions = { origin: false } // disable CORS for this request console.log('Not Allowed Origin URL: ' + origin) } callback(null, corsOptions) // callback expects two parameters: error and options } app.use(cors(corsOptions)) await app.listen(3000, function () { console.log( '[CORS-enabled->npm install -g webpack webpack-cli] web server listening on port 3000' ) }) } bootstrap()