diff --git a/packages/astro/e2e/actions-blog.test.js b/packages/astro/e2e/actions-blog.test.js index a8d9a7fc67b9..231cd49f6708 100644 --- a/packages/astro/e2e/actions-blog.test.js +++ b/packages/astro/e2e/actions-blog.test.js @@ -155,7 +155,7 @@ test.describe('Astro Actions - Blog', () => { await expect(page).toHaveURL(astro.resolveUrl('/blog/')); }); - test('Should redirect to the origin pathname when there is a rewrite', async ({ + test('Should redirect to the origin pathname when there is a rewrite from an Astro page', async ({ page, astro, }) => { @@ -166,4 +166,16 @@ test.describe('Astro Actions - Blog', () => { const p = page.locator('p').nth(0); await expect(p).toContainText('Form result: {"data":3}'); }); + + test('Should redirect to the origin pathname when there is a rewrite from the middleware', async ({ + page, + astro, + }) => { + await page.goto(astro.resolveUrl('/second-sum')); + const submitButton = page.getByTestId('submit'); + await submitButton.click(); + await expect(page).toHaveURL(astro.resolveUrl('/second-sum')); + const p = page.locator('p').nth(0); + await expect(p).toContainText('Form result: {"data":3}'); + }); }); diff --git a/packages/astro/e2e/fixtures/actions-blog/astro.config.mjs b/packages/astro/e2e/fixtures/actions-blog/astro.config.mjs index 35f7481f230e..c00c4da70df2 100644 --- a/packages/astro/e2e/fixtures/actions-blog/astro.config.mjs +++ b/packages/astro/e2e/fixtures/actions-blog/astro.config.mjs @@ -7,7 +7,7 @@ import node from '@astrojs/node'; export default defineConfig({ site: 'https://example.com', integrations: [db(), react()], - output: 'static', + output: 'server', adapter: node({ mode: 'standalone', }), diff --git a/packages/astro/e2e/fixtures/actions-blog/src/middleware.ts b/packages/astro/e2e/fixtures/actions-blog/src/middleware.ts index 53bb8235ac2a..26d9fd811486 100644 --- a/packages/astro/e2e/fixtures/actions-blog/src/middleware.ts +++ b/packages/astro/e2e/fixtures/actions-blog/src/middleware.ts @@ -1,7 +1,7 @@ import { defineMiddleware } from "astro:middleware"; export const onRequest = defineMiddleware((ctx, next) => { - if (ctx.request.method === "GET" && ctx.url.pathname === "/sum") { + if (ctx.request.method === "GET" && ctx.url.pathname === "/second-sum") { return next("/rewritten") } diff --git a/packages/astro/e2e/fixtures/actions-blog/src/pages/sum.astro b/packages/astro/e2e/fixtures/actions-blog/src/pages/sum.astro new file mode 100644 index 000000000000..ef00a5e66162 --- /dev/null +++ b/packages/astro/e2e/fixtures/actions-blog/src/pages/sum.astro @@ -0,0 +1,3 @@ +--- +return Astro.rewrite('/rewritten' + Astro.url.search) +---