fix(frontend): improve mock api error message for source ip

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-10-24 09:12:14 +02:00 committed by Erik Michelson
parent e953a5115a
commit 7037c9f6ca

View file

@ -62,8 +62,8 @@ export const respondToTestRequest = <T>(req: NextApiRequest, res: NextApiRespons
res.status(405).send('Method not allowed')
} else if (!isTestMode) {
res.status(404).send('Route only available in test mode')
} else if (req.socket.remoteAddress !== '127.0.0.1' && req.socket.remoteAddress !== '::1') {
res.status(403).send('Request must come from localhost')
} else if (!['127.0.0.1', '::1', '::ffff:127.0.0.1'].includes(req.socket.remoteAddress)) {
res.status(403).send(`Request must come from localhost but was ${req.socket.remoteAddress}`)
} else {
res.status(200).json(response())
}