diff --git a/.gitignore b/.gitignore index d1de55308..7a016a969 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ package-lock.json .pnpm-store .idea/ **/fixtures/**/.astro +**/hosted/**/.astro # ignore top-level vscode settings /.vscode/settings.json diff --git a/packages/netlify/CHANGELOG.md b/packages/netlify/CHANGELOG.md index ec78cdcd4..4c0ad5969 100644 --- a/packages/netlify/CHANGELOG.md +++ b/packages/netlify/CHANGELOG.md @@ -1,5 +1,13 @@ # @astrojs/netlify +## 6.0.1 + +### Patch Changes + +- [#481](https://github.com/withastro/adapters/pull/481) [`9d98b8a`](https://github.com/withastro/adapters/commit/9d98b8a19efdd5c7483cce70b732208093bf82b2) Thanks [@ascorbic](https://github.com/ascorbic)! - Fixes an error where edge middleware would incorrectly assign locals + +- [#488](https://github.com/withastro/adapters/pull/488) [`f3739be`](https://github.com/withastro/adapters/commit/f3739bef812aa9659ff9bdd10ba9046ac716a3d5) Thanks [@ascorbic](https://github.com/ascorbic)! - Correctly pass Netlify context in edge middleware + ## 6.0.0 ### Major Changes diff --git a/packages/netlify/package.json b/packages/netlify/package.json index 075809303..eb4d0b7ba 100644 --- a/packages/netlify/package.json +++ b/packages/netlify/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/netlify", "description": "Deploy your site to Netlify", - "version": "6.0.0", + "version": "6.0.1", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/packages/netlify/src/index.ts b/packages/netlify/src/index.ts index 6f3035073..4e87a5f05 100644 --- a/packages/netlify/src/index.ts +++ b/packages/netlify/src/index.ts @@ -289,9 +289,9 @@ export default function netlifyIntegration( export default async (request, context) => { const ctx = createContext({ request, - params: {} + params: {}, + locals: { netlify: { context } } }); - ctx.locals = { netlify: { context } } // https://docs.netlify.com/edge-functions/api/#return-a-rewrite ctx.rewrite = (target) => { if(target instanceof Request) { diff --git a/packages/netlify/test/hosted/hosted-astro-project/astro.config.mjs b/packages/netlify/test/hosted/hosted-astro-project/astro.config.mjs index 3d45722eb..94cc00f7b 100644 --- a/packages/netlify/test/hosted/hosted-astro-project/astro.config.mjs +++ b/packages/netlify/test/hosted/hosted-astro-project/astro.config.mjs @@ -4,7 +4,9 @@ import { defineConfig } from 'astro/config'; // https://astro.build/config export default defineConfig({ output: 'server', - adapter: netlify(), + adapter: netlify({ + edgeMiddleware: true, + }), image: { remotePatterns: [ { diff --git a/packages/netlify/test/hosted/hosted-astro-project/src/middleware.ts b/packages/netlify/test/hosted/hosted-astro-project/src/middleware.ts new file mode 100644 index 000000000..4ecc924a5 --- /dev/null +++ b/packages/netlify/test/hosted/hosted-astro-project/src/middleware.ts @@ -0,0 +1,11 @@ +import https from 'node:https'; + +export const onRequest = (context, next) => { + console.log(context.netlify); + context.locals.middleware = context?.locals?.netlify?.context?.geo?.country?.code ?? null; + context.locals.runtime = 'Deno' in globalThis ? 'Deno' : 'Node'; + context.locals.title = 'Middleware'; + context.locals.nodePrefixedImportExists = !!https; + + return next(); +}; diff --git a/packages/netlify/test/hosted/hosted-astro-project/src/pages/country.astro b/packages/netlify/test/hosted/hosted-astro-project/src/pages/country.astro new file mode 100644 index 000000000..cad7116d6 --- /dev/null +++ b/packages/netlify/test/hosted/hosted-astro-project/src/pages/country.astro @@ -0,0 +1,7 @@ +--- +const country = Astro.locals.middleware; +--- + +