diff --git a/server/routes/apiRoute.js b/server/routes/apiRoute.js index ed1e23c..df19d9f 100644 --- a/server/routes/apiRoute.js +++ b/server/routes/apiRoute.js @@ -246,7 +246,13 @@ export default { if (e && e.response && e.response.status) { return res.status(e.response.status).json({}); } - return res.status(408).json({}); + // return res.status(408).json({}); + if (!res.headersSent) { + return res.status(408).json({}); + } else { + // Log or handle the situation where a response was already sent + console.error('Response already sent.'); + } } }, diff --git a/server/utils/logger.js b/server/utils/logger.js index f67190c..a5c685c 100644 --- a/server/utils/logger.js +++ b/server/utils/logger.js @@ -17,16 +17,22 @@ const logger = { ignoreRoute, meta: false, msg: (req, res) => { - return `${req.method} ${req.protocol}://${req.get('host')}${req.originalUrl} (${ + return `${req.method} ${req.protocol}://${req.get('host')}${sanitizeUrl(req.originalUrl)} (${ res.statusCode }) ${Math.floor(res.responseTime / 1000)}, User-Agent: ${req.get( 'User-Agent' - )}, Referrer: ${req.get('Referrer')}, IP: ${ + )}, Referrer: ${sanitizeUrl(req.get('Referrer'))}, IP: ${ req.ip.indexOf(':') >= 0 ? req.ip.substring(req.ip.lastIndexOf(':') + 1) : req.i }`; }, }; +function sanitizeUrl(url) { + // Implement URL sanitization logic here + // For example, removing or encoding certain characters + return url.replace(/[{}]/g, encodeURIComponent); +} + export const accessLog = { ...logger, transports: [