Skip to content

Commit

Permalink
refactor: implement code suggestions
Browse files Browse the repository at this point in the history
* made it to follow DRY
  • Loading branch information
HarshPatel5940 committed Feb 10, 2024
1 parent 28e7e8f commit a6c41ad
Showing 1 changed file with 43 additions and 32 deletions.
75 changes: 43 additions & 32 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class CustomLogger implements LoggerService {
}
}

async function bootstrap() {
async function initializeSentry() {
if (!process.env.SENTRY_DSN) {
throw new Error('Missing environment variable: SENTRY_DSN')
}
Sentry.init({
dsn: process.env.SENTRY_DSN,
enabled: process.env.NODE_ENV !== 'test' && process.env.NODE_ENV !== 'e2e',
Expand All @@ -54,41 +57,49 @@ async function bootstrap() {
integrations: [new ProfilingIntegration()],
debug: process.env.NODE_ENV.startsWith('dev')
})
}

async function initializeNestApp() {
const logger = new CustomLogger()
const app = await NestFactory.create(AppModule, {
logger
})
app.use(Sentry.Handlers.requestHandler())
app.use(Sentry.Handlers.tracingHandler())

const globalPrefix = 'api'
app.setGlobalPrefix(globalPrefix)
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
transform: true
}),
new QueryTransformPipe()
)
const port = 4200
const swaggerConfig = new DocumentBuilder()
.setTitle('keyshade')
.setDescription('The keyshade API description')
.setVersion('1.0')
.build()
const document = SwaggerModule.createDocument(app, swaggerConfig)
SwaggerModule.setup('docs', app, document)
app.use(Sentry.Handlers.errorHandler())
await app.listen(port)
logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
)
}

async function bootstrap() {
await initializeSentry()
await Sentry.startSpan(
{
op: 'mainSpan',
name: 'My Main Span'
op: 'applicationBootstrap',
name: 'Application Bootstrap Process'
},
async () => {
const logger = new CustomLogger()
const app = await NestFactory.create(AppModule, {
logger
})
app.use(Sentry.Handlers.requestHandler())
app.use(Sentry.Handlers.tracingHandler())

const globalPrefix = 'api'
app.setGlobalPrefix(globalPrefix)
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
transform: true
}),
new QueryTransformPipe()
)
const port = 4200
const swaggerConfig = new DocumentBuilder()
.setTitle('keyshade')
.setDescription('The keyshade API description')
.setVersion('1.0')
.build()
const document = SwaggerModule.createDocument(app, swaggerConfig)
SwaggerModule.setup('docs', app, document)
app.use(Sentry.Handlers.errorHandler())
await app.listen(port)
logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
)
await initializeNestApp()
}
)
}
Expand Down

0 comments on commit a6c41ad

Please sign in to comment.