Skip to content

FetchEvent

Every FastEdge application is a fetch event listener. The runtime dispatches a FetchEvent for each incoming HTTP request; your handler must call event.respondWith() synchronously with a Response (or Promise<Response>).

addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event));
});
async function handleRequest(event) {
return new Response('hello', { status: 200 });
}
Property / MethodTypeDescription
requestRequestThe incoming HTTP request.
clientClientInfoInformation about the downstream client.
serverServerInfoInformation about the FastEdge POP handling the request.
respondWith(response: Response | PromiseLike<Response>) => voidSends a response back to the client.
waitUntil(promise: Promise<any>) => voidExtends the worker lifetime until the promise settles.

waitUntil — running work after the response is sent

Section titled “waitUntil — running work after the response is sent”

event.respondWith keeps the worker alive until the response is fully sent. event.waitUntil extends that lifetime further: the worker continues running until every promise registered with waitUntil has settled. This lets you do logging, telemetry, or cache warming after the client has already received its response — without making the user wait for it.

addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event));
});
async function handleRequest(event) {
// Fire-and-forget logging — runs after respondWith returns to the client.
event.waitUntil(
fetch('https://logging.example.com/log', {
method: 'POST',
body: JSON.stringify({ url: event.request.url, ip: event.client.address }),
headers: { 'content-type': 'application/json' },
}),
);
return new Response('ok', { status: 200 });
}

If a promise registered with waitUntil rejects, the worker still terminates cleanly — the rejection is logged but does not affect the response that was already sent.

Available as event.client. Fields are derived from headers the FastEdge POP injects into the request — the application does not need to parse x-forwarded-for or x-real-ip itself. The geo namespace is populated lazily on first access.

PropertyTypeDescription
addressstringIPv4 or IPv6 address of the downstream client. Empty string if unavailable.
tlsJA3MD5stringJA3 TLS-handshake fingerprint as MD5 hex. Empty for non-TLS or unavailable.
protocolstringProtocol family — "https" or "http". Not the TLS version string.
geoGeoInfoClient geographic information. Populated lazily on first access.

Available as event.client.geo.

PropertyTypeDescription
asnstringAutonomous System Number of the client’s network.
latitudenumber | nullLatitude in decimal degrees, or null if unavailable.
longitudenumber | nullLongitude in decimal degrees, or null if unavailable.
regionstringRegion or state code (subdivision).
continentstringContinent code (e.g. "EU", "NA").
countryCodestringISO 3166-1 alpha-2 country code (e.g. "PT").
countryNamestringCountry name (e.g. "Portugal").
citystringCity name. Empty when geo lookup did not resolve a city.
addEventListener('fetch', (event) => {
const { address, geo } = event.client;
console.log(`Request from ${address} in ${geo.city}, ${geo.countryCode}`);
event.respondWith(new Response('ok', { status: 200 }));
});

Available as event.server. The pop namespace is populated lazily on first access.

PropertyTypeDescription
addressstringServer-side IP address that received the request.
namestringServer hostname.
popPopInfoPOP location information. Populated lazily on first access.

Available as event.server.pop. Useful for routing decisions, geographically-aware caching keys, or telling clients which POP served them.

PropertyTypeDescription
latitudenumber | nullPOP latitude in decimal degrees, or null if unavailable.
longitudenumber | nullPOP longitude in decimal degrees, or null if unavailable.
regionstringPOP region or state code.
continentstringPOP continent code.
countryCodestringISO 3166-1 alpha-2 POP country code.
countryNamestringPOP country name.
citystringPOP city.
addEventListener('fetch', (event) => {
const { name, pop } = event.server;
console.log(`Served by ${name} in ${pop.city}, ${pop.countryCode}`);
event.respondWith(new Response('ok', { status: 200 }));
});