mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-08 21:07:46 +00:00
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>
13 lines
382 B
JavaScript
13 lines
382 B
JavaScript
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) });
|
|
}
|
|
|
|
export const config = { runtime: 'edge' };
|