Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const server = express();
const app = await NestFactory.create(AppModule, new ExpressAdapter(server));
app.use(helmet());
app.use(cookieParser());
app.enableCors(corsOptions);
app.useGlobalPipes(
new ValidationPipe({
transform: true,
})
);
// tslint:disable-next-line: no-unsafe-any
app.useWebSocketAdapter(new WsAdapter(app));
app.use('/voyager', voyagerMiddleware({ endpointUrl: '/graphql' }));
const options = new DocumentBuilder()
.setTitle('Auth example')
.setDescription('The auth API description')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('swagger', app, document);
await app.listen(8080);
}
bootstrap();
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useWebSocketAdapter(new WsAdapter(app));
// swagger setting
const options = new DocumentBuilder()
.setTitle('ptarmigan REST-API')
.setDescription('Lightning Network implementation ptarmigan REST-API')
.addBearerAuth('Authorization', 'header')
.setVersion('0.2')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);
const config = ConfigService;
Logger.log('ptarmdRpcPort: ' + config.get('ptarmigan.ptarmdRpcPort'));
Logger.log('ptarmdHost: + ' + config.get('ptarmigan.ptarmdHost'));
Logger.log('bitcoindRpcPort: ' + config.get('ptarmigan.bitcoindRpcPort'));
Logger.log('bitcoindHost: ' + config.get('ptarmigan.bitcoindHost'));
app.use(morgan('combined'));
const limit = configLoader.loadConfig(ConfigKeys.PAYLOAD_LIMIT, '20mb');
logger.log(`set json payload limit to ${limit}`);
app.use(bodyParser.json({ limit }));
app.use(bodyParser.urlencoded({ limit, extended: true }));
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
app.useGlobalInterceptors(new LoggerInterceptor());
app.useGlobalFilters(new AnyExceptionFilter());
app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
if (options.redisMode === 'redis') {
app.useWebSocketAdapter(new (require('./modules/ws/redis.adapter').RedisIoAdapter)(app));
} else if (options.redisMode === 'ws') {
app.useWebSocketAdapter(new (require('@nestjs/platform-ws').WsAdapter)(app));
}
// app.use(csurf());
// app.enableCors(); fixme temp disable for allow OPTIONS
app.enableShutdownHooks();
if (AsunaContext.isDebugMode) {
logger.log('[X] debug mode is enabled');
}
// --------------------------------------------------------------
// Setup Swagger
// --------------------------------------------------------------
if (configLoader.loadBoolConfig(ConfigKeys.SWAGGER)) {
logger.log('[X] init swagger at /swagger');
await createInitialSchemaIfNeeded(conn, env.DbName, logger);
await checkSchemaVersion(conn, logger);
await conn.close();
}
} else {
await new Promise(resolve => setTimeout(resolve, 3000)); // let master process do it's thing, create schema and all;
}
const app = await NestFactory.create(AppModule);
app.useStaticAssets(env.localStaticsPath);
app.setBaseViewsDir(env.localStaticsPath);
app.engine('.vm', velocityEngine());
app.use(cookieParser());
app.useWebSocketAdapter(new WsAdapter(app));
await app.listen(env.HttpPort);
}
bootstrap();
const bootstrap = async () => {
const mod = await Test.createTestingModule({
imports: [EventsModule],
}).compile();
app = mod.createNestApplication();
app.useWebSocketAdapter(new WsAdapter());
await app.listen(7000);
};
beforeAll(async () => {
const mod = await Test.createTestingModule({
imports: [EventsModule],
}).compile();
app = mod.createNestApplication();
app.useWebSocketAdapter(new WsAdapter());
await app.listen(testConfig.port);
});
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger: console,
cors: true,
});
await app.useWebSocketAdapter(new WsAdapter(app)).listen(port);
}
bootstrap();
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useWebSocketAdapter(new WsAdapter(app));
await app.listen(3000);
}
bootstrap();