Created
May 8, 2024 22:03
-
-
Save yordis/f5ab0295cf58b58a49519f247819fe31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://twitter.com/alchemist_ubi/status/1786275138532790439 | |
function proxy(proxy: string, req: Request): Request { | |
const url = new URL(proxy); | |
const originUrl = new URL(req.url); | |
const header = new Headers(req.headers); | |
header.set('X-Forwarded-For', 'some-ip'); | |
url.pathname = originUrl.pathname; | |
// Do other stuff mapping the `req` to the proxy req .... | |
// doesnot matter for the example | |
return new Request(url, { | |
...req, | |
headers: req.headers, | |
}); | |
} | |
fetch(proxy('https://example.com', new Request('/api/data'))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment