Open
Description
What is the improvement or update you wish to see?
When using pages router, we can use context on api routers:
import { NextResponse } from 'next/server';
import type { NextFetchEvent, NextRequest } from 'next/server';
export const config = {
runtime: 'edge',
};
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
async function getAlbum() {
const res = await fetch('https://jsonplaceholder.typicode.com/albums/1');
await wait(10000);
return res.json();
}
export default function MyEdgeFunction(
request: NextRequest,
context: NextFetchEvent,
) {
context.waitUntil(getAlbum().then((json) => console.log({ json })));
return NextResponse.json({
name: `Hello, from ${request.url} I'm an Edge Function!`,
});
}
while using app router, we got this from doc:
Currently, the only value of context is params, which is an object containing the dynamic route parameters for the current route.
so I am wondering how to use NextFetchEvent with route handler?
Is there any context that might help us understand?
I am trying to keep the function running after a response has been sent, as the vercel doc navigated, we can use waitUntil()
, but it seems not approachable in App Router and Route Handler, can I get any thoughts? thanks
Does the docs page already exist? Please link to it.
https://nextjs.org/docs/app/api-reference/file-conventions/route#context-optional