From a74453a5458f3b3655ddb24547b11fa7b36a5988 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 6 Oct 2023 09:10:58 +1030 Subject: [PATCH] DO-1484: make user-agent visible for easier debugging --- packages/prerender-fargate/lib/prerender/server.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/prerender-fargate/lib/prerender/server.js b/packages/prerender-fargate/lib/prerender/server.js index a4913bf2..463ee56f 100644 --- a/packages/prerender-fargate/lib/prerender/server.js +++ b/packages/prerender-fargate/lib/prerender/server.js @@ -12,8 +12,12 @@ const server = prerender({ server.use({ requestReceived: (req, res, next) => { + console.log(`${new Date().toISOString()} User-Agent: "${req.get('user-agent')}" ${req.prerender.reqId} ${req.prerender.url}`); let auth = req.headers['x-prerender-token']; - if (!auth) return res.send(401); + if (!auth) { + console.log(`${new Date().toISOString()} "${req.get('user-agent')}" ${req.prerender.reqId} Authentication header not found.`); + return res.send(401); + } // compare credentials in header to list of allowed credentials const tokenAllowList = process.env.TOKEN_LIST.toString().split(','); @@ -24,7 +28,10 @@ server.use({ if (authenticated) break; } - if (!authenticated) return res.send(401); + if (!authenticated) { + console.log(`${new Date().toISOString()} "${req.get('user-agent')}" ${req.prerender.reqId} Authentication Failed.`); + return res.send(401); + } return next(); },