1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-06-16 17:39:18 +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:
2024-01-22 23:45:48 +01:00
parent 0146765e7a
commit e6a8c1dd71
4 changed files with 21 additions and 0 deletions

View File

@ -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`);