mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-07-30 19:40:48 +00:00
feat(server): Add better logging to detect potential errors
Signed-off-by: Avior <f.bouillon@aptatio.com>
This commit is contained in:
@ -1,14 +1,14 @@
|
||||
import express from 'express'
|
||||
import graphql from './V2/graphql'
|
||||
import jsonEndpoints from './V2/endpoints/jsonEndpoints'
|
||||
import status from './status'
|
||||
import jsonEndpoints from './V2/endpoints/jsonEndpoints'
|
||||
import graphql from './V2/graphql'
|
||||
// Current API version
|
||||
const VERSION = 2
|
||||
|
||||
// Init Express server
|
||||
const server = express()
|
||||
|
||||
// Set global headers
|
||||
// Set CORS global headers
|
||||
server.use((_, res, next) => {
|
||||
res
|
||||
.setHeader('Access-Control-Allow-Origin', '*')
|
||||
@ -18,6 +18,19 @@ server.use((_, res, next) => {
|
||||
next()
|
||||
})
|
||||
|
||||
// Route logging / Error logging for debugging
|
||||
server.use((req, res, next) => {
|
||||
res.on('close', () => {
|
||||
console.log(`[${new Date().toISOString()}]: ${req.method.padStart(7, ' ')} ${res.statusCode} ${(req.baseUrl ?? '') + req.url}`)
|
||||
})
|
||||
res.on('error', (err) => {
|
||||
console.error('Error:')
|
||||
console.error(err)
|
||||
})
|
||||
|
||||
next()
|
||||
})
|
||||
|
||||
server.get('/', (_, res) => {
|
||||
res.redirect('https://www.tcgdex.dev/?ref=api.tcgdex.net')
|
||||
})
|
||||
|
Reference in New Issue
Block a user