From 42a21b5da631948da4495062a6ef30fbb91abd05 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 26 Jul 2023 07:58:57 -0400 Subject: [PATCH] Prevent building .html files in hybrid mode (#7805) * Prevent building .html files in hybrid mode * Adding a changeset --- .changeset/ninety-kids-fail.md | 5 ++++ .../netlify/src/integration-functions.ts | 1 + .../fixtures/redirects/src/pages/index.astro | 9 +++++++ .../fixtures/redirects/src/pages/nope.astro | 3 +++ .../src/pages/team/articles/[...slug].astro | 27 +++++++++++++++++++ .../netlify/test/functions/redirects.test.js | 15 ++++++++--- 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 .changeset/ninety-kids-fail.md create mode 100644 packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/index.astro create mode 100644 packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/nope.astro create mode 100644 packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/team/articles/[...slug].astro diff --git a/.changeset/ninety-kids-fail.md b/.changeset/ninety-kids-fail.md new file mode 100644 index 000000000000..1fc3145d1993 --- /dev/null +++ b/.changeset/ninety-kids-fail.md @@ -0,0 +1,5 @@ +--- +'@astrojs/netlify': patch +--- + +Prevent building .html file redirects in hybrid mode diff --git a/packages/integrations/netlify/src/integration-functions.ts b/packages/integrations/netlify/src/integration-functions.ts index 28f828e48ff6..a950167e5b0d 100644 --- a/packages/integrations/netlify/src/integration-functions.ts +++ b/packages/integrations/netlify/src/integration-functions.ts @@ -40,6 +40,7 @@ function netlifyFunctions({ updateConfig({ outDir, build: { + redirects: false, client: outDir, server: new URL('./.netlify/functions-internal/', config.root), }, diff --git a/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/index.astro b/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/index.astro new file mode 100644 index 000000000000..41f740c4cbfa --- /dev/null +++ b/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/index.astro @@ -0,0 +1,9 @@ +--- +export const prerender = false; +--- + +Testing + +

Testing

+ + diff --git a/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/nope.astro b/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/nope.astro new file mode 100644 index 000000000000..f48d767ee180 --- /dev/null +++ b/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/nope.astro @@ -0,0 +1,3 @@ +--- +return Astro.redirect('/'); +--- diff --git a/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/team/articles/[...slug].astro b/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/team/articles/[...slug].astro new file mode 100644 index 000000000000..996cd989ee48 --- /dev/null +++ b/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/team/articles/[...slug].astro @@ -0,0 +1,27 @@ +--- +export const prerender = false; + +export const getStaticPaths = (async () => { + const posts = [ + { slug: 'one', data: {draft: false, title: 'One'} }, + { slug: 'two', data: {draft: false, title: 'Two'} } + ]; + return posts.map((post) => { + return { + params: { slug: post.slug }, + props: { draft: post.data.draft, title: post.data.title }, + }; + }); +}) + +const { slug } = Astro.params; +const { title } = Astro.props; +--- + + + { title } + + +

{ title }

+ + diff --git a/packages/integrations/netlify/test/functions/redirects.test.js b/packages/integrations/netlify/test/functions/redirects.test.js index 39c496cdf21a..1995718f8157 100644 --- a/packages/integrations/netlify/test/functions/redirects.test.js +++ b/packages/integrations/netlify/test/functions/redirects.test.js @@ -8,10 +8,10 @@ describe('SSG - Redirects', () => { before(async () => { fixture = await loadFixture({ - root: new URL('../static/fixtures/redirects/', import.meta.url).toString(), - output: 'server', + root: new URL('../functions/fixtures/redirects/', import.meta.url).toString(), + output: 'hybrid', adapter: netlifyAdapter({ - dist: new URL('../static/fixtures/redirects/dist/', import.meta.url), + dist: new URL('../functions/fixtures/redirects/dist/', import.meta.url), }), site: `http://example.com`, integrations: [testIntegration()], @@ -45,4 +45,13 @@ describe('SSG - Redirects', () => { ]); expect(redirects).to.matchSnapshot(); }); + + it('Does not create .html files', async () => { + try { + await fixture.readFile('/other/index.html'); + expect(false).to.equal(true, 'this file should not exist'); + } catch { + expect(true).to.equal(true); + } + }); });