2020-11-17 22:26:03 +01:00
|
|
|
import { ValidationPipe } from "@nestjs/common";
|
|
|
|
|
import { ConfigService } from "@nestjs/config";
|
2020-01-25 22:19:14 +01:00
|
|
|
import { NestFactory } from "@nestjs/core";
|
2020-01-26 19:07:15 +01:00
|
|
|
import { NestExpressApplication } from "@nestjs/platform-express";
|
2020-02-01 16:11:48 +01:00
|
|
|
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
2020-01-25 22:19:14 +01:00
|
|
|
import { AppModule } from "./app.module";
|
2020-11-17 22:26:03 +01:00
|
|
|
import * as Sentry from "@sentry/node";
|
|
|
|
|
import { RavenInterceptor } from "nest-raven";
|
|
|
|
|
|
|
|
|
|
function setupSentry(
|
|
|
|
|
app: NestExpressApplication,
|
|
|
|
|
configService: ConfigService
|
|
|
|
|
) {
|
|
|
|
|
Sentry.init({
|
|
|
|
|
dsn: configService.get<string>("SENTRY_DSN"),
|
|
|
|
|
integrations: [
|
|
|
|
|
new Sentry.Integrations.OnUncaughtException(),
|
|
|
|
|
new Sentry.Integrations.OnUnhandledRejection(),
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.useGlobalInterceptors(new RavenInterceptor());
|
|
|
|
|
}
|
2020-01-25 22:19:14 +01:00
|
|
|
|
|
|
|
|
async function bootstrap() {
|
2020-01-26 19:07:15 +01:00
|
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
2020-05-09 16:29:17 +02:00
|
|
|
app.useGlobalPipes(
|
|
|
|
|
new ValidationPipe({
|
|
|
|
|
transform: true,
|
|
|
|
|
transformOptions: { enableImplicitConversion: true },
|
|
|
|
|
})
|
|
|
|
|
);
|
2020-05-03 04:32:43 +02:00
|
|
|
app.enableShutdownHooks();
|
2020-01-26 19:07:15 +01:00
|
|
|
|
2020-11-17 22:26:03 +01:00
|
|
|
const configService = app.get<ConfigService>(ConfigService);
|
|
|
|
|
|
|
|
|
|
if (configService.get<boolean>("SENTRY_ENABLED")) {
|
|
|
|
|
setupSentry(app, configService);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-01 16:11:48 +01:00
|
|
|
// Setup API Docs
|
|
|
|
|
const options = new DocumentBuilder()
|
|
|
|
|
.setTitle("Listory")
|
|
|
|
|
.setDescription("Track and analyze your Spotify Listens")
|
|
|
|
|
.setVersion("1.0")
|
|
|
|
|
.addBearerAuth()
|
|
|
|
|
.addTag("user")
|
|
|
|
|
.addTag("listens")
|
|
|
|
|
.addTag("auth")
|
|
|
|
|
.build();
|
|
|
|
|
const document = SwaggerModule.createDocument(app, options);
|
|
|
|
|
SwaggerModule.setup("api/docs", app, document);
|
2020-01-26 19:07:15 +01:00
|
|
|
|
2020-01-25 22:19:14 +01:00
|
|
|
await app.listen(3000);
|
|
|
|
|
}
|
2020-11-17 22:26:03 +01:00
|
|
|
|
2020-01-25 22:19:14 +01:00
|
|
|
bootstrap();
|