Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9bd3b83

Browse files
committed
Fix port parseInt error handling
parseInt returns NaN rather than throwing.
1 parent 2c9b4e7 commit 9bd3b83

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/node/routes/pathProxy.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ const getProxyTarget = (
1313
): string => {
1414
// If there is a base path, strip it out.
1515
const base = (req as any).base || ""
16-
let port: number
17-
try {
18-
port = parseInt(req.params.port, 10)
19-
} catch (err) {
16+
const port = parseInt(req.params.port, 10)
17+
if (isNaN(port)) {
2018
throw new HttpError("Invalid port", HttpCode.BadRequest)
2119
}
2220
return `http://0.0.0.0:${port}${opts?.proxyBasePath || ""}/${req.originalUrl.slice(base.length)}`

0 commit comments

Comments
 (0)