Fix port parseInt error handling

parseInt returns NaN rather than throwing.
This commit is contained in:
Asher
2025-05-08 14:20:45 -08:00
parent 2c9b4e7fd5
commit 9bd3b83ef5

View File

@ -13,10 +13,8 @@ const getProxyTarget = (
): string => {
// If there is a base path, strip it out.
const base = (req as any).base || ""
let port: number
try {
port = parseInt(req.params.port, 10)
} catch (err) {
const port = parseInt(req.params.port, 10)
if (isNaN(port)) {
throw new HttpError("Invalid port", HttpCode.BadRequest)
}
return `http://0.0.0.0:${port}${opts?.proxyBasePath || ""}/${req.originalUrl.slice(base.length)}`