Skip to content

Commit

Permalink
DO-1484: make user-agent visible for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Park committed Oct 5, 2023
1 parent 0b880f3 commit a74453a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/prerender-fargate/lib/prerender/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(',');
Expand All @@ -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();
},
Expand Down

0 comments on commit a74453a

Please sign in to comment.