From fe67ce13a23b8bd12b675c4baab6540813691baf Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Wed, 12 Jun 2024 16:13:14 +0000 Subject: [PATCH] fix(ur): return 404 if process id cannot be extracted from request #790 --- servers/ur/src/proxy.js | 2 ++ servers/ur/src/redirect.js | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/servers/ur/src/proxy.js b/servers/ur/src/proxy.js index 591448921..63b496502 100644 --- a/servers/ur/src/proxy.js +++ b/servers/ur/src/proxy.js @@ -66,6 +66,8 @@ export function proxyWith ({ aoUnit, hosts, subrouterUrl, surUrl, owners, proces always(async (req, res) => { const processId = await processIdFromRequest(req) + if (!processId) return res.status(404).send({ error: 'Process id not found on request' }) + async function revProxy ({ failoverAttempt, err }) { /** * In cases where we have to consume the request stream before proxying diff --git a/servers/ur/src/redirect.js b/servers/ur/src/redirect.js index 01c739b01..e16df11a5 100644 --- a/servers/ur/src/redirect.js +++ b/servers/ur/src/redirect.js @@ -18,8 +18,13 @@ export function redirectWith ({ aoUnit, hosts, subrouterUrl, surUrl, owners, pro * by the injected business logic. */ const redirectHandler = ({ processIdFromRequest }) => { + // TODO: should we compose an error handler, similar to proxy.js? + // for now, just keeping as is. return async (req, res) => { const processId = await processIdFromRequest(req) + + if (!processId) return res.status(404).send({ error: 'Process id not found on request' }) + const host = await determineHost({ processId }) _logger('Redirecting process %s to host %s', processId, host)