diff --git a/server/README.md b/server/README.md index c7d89e741..f544001c7 100644 --- a/server/README.md +++ b/server/README.md @@ -40,6 +40,11 @@ npm run build npm run start ``` +### Envs + +you can add environment variables to add features to the server: +- SENTRY_DSN: the DSN to a sentry compatible server to allow to catch errors + ### Using Docker Go to the parent directory and build the Dockerfile! diff --git a/server/bun.lockb b/server/bun.lockb index 675c6cbd5..c549c9c34 100644 Binary files a/server/bun.lockb and b/server/bun.lockb differ diff --git a/server/package.json b/server/package.json index e847b132f..bb92056f7 100644 --- a/server/package.json +++ b/server/package.json @@ -12,6 +12,7 @@ "dependencies": { "@dzeio/config": "^1", "@dzeio/object-util": "^1", + "@sentry/node": "^7", "@tcgdex/sdk": "^2", "apicache": "^1", "express": "^4", diff --git a/server/src/index.ts b/server/src/index.ts index bd9cbc626..35405ac53 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,13 +1,24 @@ +import Sentry from '@sentry/node' import express from 'express' import jsonEndpoints from './V2/endpoints/jsonEndpoints' import graphql from './V2/graphql' import status from './status' + // Current API version const VERSION = 2 // Init Express server const server = express() +// allow to catch servers errors +const sentryDSN = process.env.SENTRY_DSN + +if (sentryDSN) { + Sentry.init({ dsn: sentryDSN}) + + server.use(Sentry.Handlers.requestHandler()) +} + // Route logging / Error logging for debugging server.use((req, res, next) => { const now = new Date() @@ -71,6 +82,10 @@ server.use(`/v${VERSION}`, jsonEndpoints) // Status page server.use('/status', status) +if (sentryDSN) { + server.use(Sentry.Handlers.errorHandler()) +} + // Start server server.listen(3000) console.log(`🚀 Server ready at localhost:3000`);