diff options
author | 2023-08-11 19:39:44 +0530 | |
---|---|---|
committer | 2023-08-11 19:39:44 +0530 | |
commit | f974c95a27ccbf91adbc66f6f1433f4cf11be33e (patch) | |
tree | de4c8f89c7e6dcbec410f330c36f71cf1904ec4d /packages/integrations/netlify/src/netlify-functions.ts | |
parent | 6a9fb2d95d309ba83c8337f68aed6f4e6f00be99 (diff) | |
download | astro-f974c95a27ccbf91adbc66f6f1433f4cf11be33e.tar.gz astro-f974c95a27ccbf91adbc66f6f1433f4cf11be33e.tar.zst astro-f974c95a27ccbf91adbc66f6f1433f4cf11be33e.zip |
Add Incremental Static Regeneration support for the Netlify's on-demand builders adapter (#7975)
* feat(netlify): expose builders ttl as a local
* add changeset
* docs(netlify): caching using on-demand builders
* reword readme section
* Update packages/integrations/netlify/package.json
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
* include builders-types.d.ts in the distribution
* document caveat regarding query params
* update changeset
* mutation -> function
* locals.netlify -> locals.runtime
* update types and changeset
* Apply suggestions from code review
Co-authored-by: Elian ☕️ <hello@elian.codes>
* Apply suggestions from code review
Co-authored-by: Elian ☕️ <hello@elian.codes>
---------
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Co-authored-by: Elian ☕️ <hello@elian.codes>
Diffstat (limited to 'packages/integrations/netlify/src/netlify-functions.ts')
-rw-r--r-- | packages/integrations/netlify/src/netlify-functions.ts | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/packages/integrations/netlify/src/netlify-functions.ts b/packages/integrations/netlify/src/netlify-functions.ts index cc6636ec4..459c6b9b9 100644 --- a/packages/integrations/netlify/src/netlify-functions.ts +++ b/packages/integrations/netlify/src/netlify-functions.ts @@ -68,18 +68,28 @@ export const createExports = (manifest: SSRManifest, args: Args) => { init.body = typeof requestBody === 'string' ? Buffer.from(requestBody, encoding) : requestBody; } + const request = new Request(rawUrl, init); const routeData = app.match(request); const ip = headers['x-nf-client-connection-ip']; Reflect.set(request, clientAddressSymbol, ip); - let locals = {}; + + let locals: Record<string, unknown> = {}; + if (request.headers.has(ASTRO_LOCALS_HEADER)) { let localsAsString = request.headers.get(ASTRO_LOCALS_HEADER); if (localsAsString) { locals = JSON.parse(localsAsString); } } + + let responseTtl = undefined; + + locals.runtime = builders + ? { setBuildersTtl(ttl: number) { responseTtl = ttl } } + : {} + const response: Response = await app.render(request, routeData, locals); const responseHeaders = Object.fromEntries(response.headers.entries()); @@ -99,6 +109,7 @@ export const createExports = (manifest: SSRManifest, args: Args) => { headers: responseHeaders, body: responseBody, isBase64Encoded: responseIsBase64Encoded, + ttl: responseTtl, }; const cookies = response.headers.get('set-cookie'); |