1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-04-23 03:12:10 +00:00

chore: Add error handling directing to a Glitchtip server to log errors

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
Florian Bouillon 2024-01-22 23:45:48 +01:00
parent 0146765e7a
commit e6a8c1dd71
4 changed files with 21 additions and 0 deletions

View File

@ -40,6 +40,11 @@ npm run build
npm run start 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 ### Using Docker
Go to the parent directory and build the Dockerfile! Go to the parent directory and build the Dockerfile!

Binary file not shown.

View File

@ -12,6 +12,7 @@
"dependencies": { "dependencies": {
"@dzeio/config": "^1", "@dzeio/config": "^1",
"@dzeio/object-util": "^1", "@dzeio/object-util": "^1",
"@sentry/node": "^7",
"@tcgdex/sdk": "^2", "@tcgdex/sdk": "^2",
"apicache": "^1", "apicache": "^1",
"express": "^4", "express": "^4",

View File

@ -1,13 +1,24 @@
import Sentry from '@sentry/node'
import express from 'express' import express from 'express'
import jsonEndpoints from './V2/endpoints/jsonEndpoints' import jsonEndpoints from './V2/endpoints/jsonEndpoints'
import graphql from './V2/graphql' import graphql from './V2/graphql'
import status from './status' import status from './status'
// Current API version // Current API version
const VERSION = 2 const VERSION = 2
// Init Express server // Init Express server
const server = express() 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 // Route logging / Error logging for debugging
server.use((req, res, next) => { server.use((req, res, next) => {
const now = new Date() const now = new Date()
@ -71,6 +82,10 @@ server.use(`/v${VERSION}`, jsonEndpoints)
// Status page // Status page
server.use('/status', status) server.use('/status', status)
if (sentryDSN) {
server.use(Sentry.Handlers.errorHandler())
}
// Start server // Start server
server.listen(3000) server.listen(3000)
console.log(`🚀 Server ready at localhost:3000`); console.log(`🚀 Server ready at localhost:3000`);