Skip to content

Instantly share code, notes, and snippets.

@calvintwr
Created January 7, 2022 12:43
Show Gist options
  • Save calvintwr/bc01a3ed2a1267f18ea1dc2a5d391bbf to your computer and use it in GitHub Desktop.
Save calvintwr/bc01a3ed2a1267f18ea1dc2a5d391bbf to your computer and use it in GitHub Desktop.
import { ConfigModule } from '@nestjs/config'
ConfigModule.forRoot()
require('module-alias/register')
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'
import { NestFactory } from '@nestjs/core'
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'
import { AppModule } from './app.module'
import { fastifyHelmet } from 'fastify-helmet'
new FastifyAdapter()
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
)
app.enableCors()
const config = new DocumentBuilder()
.setTitle('Malt')
.setDescription('THE MALT API')
.setVersion('1.0')
.addTag('malt')
.build()
const document = SwaggerModule.createDocument(app, config)
SwaggerModule.setup('api', app, document)
// // CSP/SSL error fix for Swagger
await app.register(fastifyHelmet, {
contentSecurityPolicy: {
directives: {
defaultSrc: [`'self'`],
styleSrc: [`'self'`, `'unsafe-inline'`],
imgSrc: [`'self'`, 'data:', 'validator.swagger.io'],
scriptSrc: [`'self'`, `https: 'unsafe-inline'`],
},
},
})
await app.listen(process.env.PORT || 3000)
console.log('App running on http://localhost:3000')
}
bootstrap()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment