summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/netlify/test')
-rw-r--r--packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs4
-rw-r--r--packages/integrations/netlify/test/hosted/hosted-astro-project/package.json2
-rw-r--r--packages/integrations/netlify/test/hosted/hosted-astro-project/src/middleware.ts11
-rw-r--r--packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/country.astro7
-rw-r--r--packages/integrations/netlify/test/hosted/hosted.test.js11
5 files changed, 31 insertions, 4 deletions
diff --git a/packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs b/packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs
index 3d45722eb..94cc00f7b 100644
--- a/packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs
+++ b/packages/integrations/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/integrations/netlify/test/hosted/hosted-astro-project/package.json b/packages/integrations/netlify/test/hosted/hosted-astro-project/package.json
index ad0fb85bb..8d690b9e5 100644
--- a/packages/integrations/netlify/test/hosted/hosted-astro-project/package.json
+++ b/packages/integrations/netlify/test/hosted/hosted-astro-project/package.json
@@ -7,6 +7,6 @@
},
"dependencies": {
"@astrojs/netlify": "workspace:*",
- "astro": "^5.0.0"
+ "astro": "^5.0.5"
}
}
diff --git a/packages/integrations/netlify/test/hosted/hosted-astro-project/src/middleware.ts b/packages/integrations/netlify/test/hosted/hosted-astro-project/src/middleware.ts
new file mode 100644
index 000000000..4ecc924a5
--- /dev/null
+++ b/packages/integrations/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/integrations/netlify/test/hosted/hosted-astro-project/src/pages/country.astro b/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/country.astro
new file mode 100644
index 000000000..cad7116d6
--- /dev/null
+++ b/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/country.astro
@@ -0,0 +1,7 @@
+---
+const country = Astro.locals.middleware;
+---
+
+<h1>{country}</h1>
+<h3>{country ? 'has context' : 'no context'}</h3>
+<h2>{Astro.locals.runtime}</h2>
diff --git a/packages/integrations/netlify/test/hosted/hosted.test.js b/packages/integrations/netlify/test/hosted/hosted.test.js
index 237ba5998..2c40e3a69 100644
--- a/packages/integrations/netlify/test/hosted/hosted.test.js
+++ b/packages/integrations/netlify/test/hosted/hosted.test.js
@@ -12,10 +12,17 @@ describe('Hosted Netlify Tests', () => {
assert.equal(image.status, 200);
});
+ it('passes context from edge middleware', async () => {
+ const response = await fetch(`${NETLIFY_TEST_URL}/country`);
+ const body = await response.text();
+ assert.match(body, /has context/);
+ assert.match(body, /Deno/);
+ });
+
it('Server returns fresh content', async () => {
- const responseOne = await fetch(`${NETLIFY_TEST_URL}/time`);
+ const responseOne = await fetch(`${NETLIFY_TEST_URL}/time`).then((res) => res.text());
- const responseTwo = await fetch(`${NETLIFY_TEST_URL}/time`);
+ const responseTwo = await fetch(`${NETLIFY_TEST_URL}/time`).then((res) => res.text());
assert.notEqual(responseOne.body, responseTwo.body);
});