Open History to see the last commit
1import { DurableObject } from 'cloudflare:workers'
2
3type EgressHandler = NonNullable<InstanceType<typeof DurableObject>['fetch']>
4
5/**
6 * Forwards a request from where this object lives (eastern North America;
7 * see `usEgressFetch` in `providers/us-egress.ts`). It stores nothing; its
8 * location only decides where the outbound fetch runs.
9 */
10export class UsEgress extends DurableObject {
11 // The casts bridge workers-types' Request/Response and the DOM ones the
12 // global fetch is typed with here; they are the same runtime classes.
13 override fetch(
14 request: Parameters<EgressHandler>[0],
15 ): ReturnType<EgressHandler> {
16 return fetch(
17 request as unknown as Request,
18 ) as unknown as ReturnType<EgressHandler>
19 }
20}