doc: improve code snippet alternative of url.parse() using WHATWG URL

PR-URL: https://github.com/nodejs/node/pull/60209
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Steven 2025-10-12 21:50:34 -04:00 committed by GitHub
parent da9cd745c8
commit 1cd16e5355
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1853,7 +1853,7 @@ input. CVEs are not issued for `url.parse()` vulnerabilities. Use the
function getURL(req) {
const proto = req.headers['x-forwarded-proto'] || 'https';
const host = req.headers['x-forwarded-host'] || req.headers.host || 'example.com';
return new URL(req.url || '/', `${proto}://${host}`);
return new URL(`${proto}://${host}${req.url || '/'}`);
}
```
@ -1863,7 +1863,7 @@ use the example below:
```js
function getURL(req) {
return new URL(req.url || '/', 'https://example.com');
return new URL(`https://example.com${req.url || '/'}`);
}
```