mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 04:22:13 +00:00
Make waitUntil consistent for Node.js & Edge (#11553)
This PR makes `waitUntil` consistent when interacting with it via `vc
dev`. That includes:
**be possible to call `waitUntil` from the context second argument in
web handlers functions (Node.js & Edge)**:
```js
export function GET(request, { waitUntil }) {
waitUntil(fetch('https://vercel.com'));
return new Response('OK');
}
```
**be possible to call `waitUntil` imported from `@vercel/functions`**
(Node.js & Edge):
```js
import { waitUntil } from '@vercel/functions';
export function GET(request) {
waitUntil(fetch('https://vercel.com'));
return new Response('OK');
}
```
Additionally, `@vercel/functions` can be adopted for other framework to
take advantage of this pattern at Vercel.
---------
Co-authored-by: Javi Velasco <javier.velasco86@gmail.com>
This commit is contained in:
10
packages/node/test/dev-fixtures/wait-until-ctx-node.js
Normal file
10
packages/node/test/dev-fixtures/wait-until-ctx-node.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const baseUrl = ({ headers }) =>
|
||||
`${headers.get('x-forwarded-proto')}://${headers.get('x-forwarded-host')}`;
|
||||
|
||||
export function GET(request, ctx) {
|
||||
const { searchParams } = new URL(request.url, baseUrl(request));
|
||||
const url = searchParams.get('url');
|
||||
|
||||
ctx.waitUntil(fetch(url));
|
||||
return Response.json({ keys: Object.keys(ctx) });
|
||||
}
|
||||
Reference in New Issue
Block a user