mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat(api): setup optional sentry error reporting
This commit is contained in:
parent
d620c03219
commit
56db4cd2e1
5 changed files with 2201 additions and 71 deletions
2234
package-lock.json
generated
2234
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -35,10 +35,12 @@
|
|||
"@nestjs/swagger": "4.7.3",
|
||||
"@nestjs/terminus": "7.0.1",
|
||||
"@nestjs/typeorm": "7.1.4",
|
||||
"@sentry/node": "^5.27.4",
|
||||
"class-transformer": "0.3.1",
|
||||
"class-validator": "0.12.2",
|
||||
"cookie-parser": "1.4.5",
|
||||
"date-fns": "2.16.1",
|
||||
"nest-raven": "^7.0.0",
|
||||
"nestjs-typeorm-paginate": "2.2.1",
|
||||
"passport": "0.4.1",
|
||||
"passport-jwt": "4.0.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Module } from "@nestjs/common";
|
||||
import { ScheduleModule } from "@nestjs/schedule";
|
||||
import { ServeStaticModule } from "@nestjs/serve-static";
|
||||
import { RavenModule } from "nest-raven";
|
||||
import { join } from "path";
|
||||
import { AuthModule } from "./auth/auth.module";
|
||||
import { ConfigModule } from "./config/config.module";
|
||||
|
|
@ -23,6 +24,7 @@ import { UsersModule } from "./users/users.module";
|
|||
rootPath: join(__dirname, "..", "static"),
|
||||
exclude: ["/api*"],
|
||||
}),
|
||||
RavenModule,
|
||||
AuthModule,
|
||||
UsersModule,
|
||||
SourcesModule,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,13 @@ import { ConfigModule as NestConfigModule } from "@nestjs/config";
|
|||
DB_USERNAME: Joi.string().required(),
|
||||
DB_PASSWORD: Joi.string().required(),
|
||||
DB_DATABASE: Joi.string().required(),
|
||||
|
||||
// Sentry (Optional)
|
||||
SENTRY_ENABLED: Joi.boolean().default(false),
|
||||
SENTRY_DSN: Joi.string().when("SENTRY_ENABLED", {
|
||||
is: Joi.valid(true),
|
||||
then: Joi.required(),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
|
|
|
|||
27
src/main.ts
27
src/main.ts
|
|
@ -1,8 +1,26 @@
|
|||
import { ValidationPipe } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import { NestExpressApplication } from "@nestjs/platform-express";
|
||||
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
||||
import { AppModule } from "./app.module";
|
||||
import { ValidationPipe } from "@nestjs/common";
|
||||
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());
|
||||
}
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
||||
|
|
@ -14,6 +32,12 @@ async function bootstrap() {
|
|||
);
|
||||
app.enableShutdownHooks();
|
||||
|
||||
const configService = app.get<ConfigService>(ConfigService);
|
||||
|
||||
if (configService.get<boolean>("SENTRY_ENABLED")) {
|
||||
setupSentry(app, configService);
|
||||
}
|
||||
|
||||
// Setup API Docs
|
||||
const options = new DocumentBuilder()
|
||||
.setTitle("Listory")
|
||||
|
|
@ -29,4 +53,5 @@ async function bootstrap() {
|
|||
|
||||
await app.listen(3000);
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue