McSneaky
01/08/2024, 2:28 PMts
import { Router } from 'itty-router';
const router = Router();
router.get('/edge/backporter', async (request) => {
request.query = '?foobar' // modify request
// Set URL to specific URL in other worker
request.url = '/edge/v1' // Error, cannot set read-only property
return env.BINDING.fetch(request);
}
And on BINDING
worker I have router that responds to certain URL only
https://example.com/edge/v1
ts
import { Router } from 'itty-router';
const router = Router();
router.get('/edge/v1', async (request) => { ... }
I'd like to make sure request from first worker ends up in /edge/v1
, but it never does, since I can't change request URL, nor can I request.clone()
, since then URL would match /edge/backporter
and not /edge/v1
Is anything like this possible?kian
01/08/2024, 2:29 PMenv.BINDING.fetch("http://service/edge/v1", request)
McSneaky
01/08/2024, 2:30 PMMcSneaky
01/08/2024, 2:31 PMkian
01/08/2024, 2:50 PMfetch()
API looks like this:
ts
fetch(
input: RequestInfo,
init?: RequestInit<RequestInitCfProperties>
): Promise<Response>;
RequestInfo
is either a Request, a string or a URL.
In this case, we pass a string (http://service/edge/v1
) and pass the original Request to the optional init
property to carry over everything in RequestInit
, like `method`/`headers`/`body`/`cf`.kian
01/08/2024, 2:50 PMjs
const url = new URL(request.url);
url.pathname = "/edge/v1"
await fetch(url, request);
etcMcSneaky
01/08/2024, 2:53 PMrequest.clone()
Which made me think it's not possible to modify the requestMcSneaky
01/08/2024, 2:54 PM