Skip to content

Commit 42a21b5

Browse files
authored
Prevent building .html files in hybrid mode (#7805)
* Prevent building .html files in hybrid mode * Adding a changeset
1 parent db8c040 commit 42a21b5

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

.changeset/ninety-kids-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/netlify': patch
3+
---
4+
5+
Prevent building .html file redirects in hybrid mode

packages/integrations/netlify/src/integration-functions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function netlifyFunctions({
4040
updateConfig({
4141
outDir,
4242
build: {
43+
redirects: false,
4344
client: outDir,
4445
server: new URL('./.netlify/functions-internal/', config.root),
4546
},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
export const prerender = false;
3+
---
4+
<html>
5+
<head><title>Testing</title></head>
6+
<body>
7+
<h1>Testing</h1>
8+
</body>
9+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
return Astro.redirect('/');
3+
---
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
export const prerender = false;
3+
4+
export const getStaticPaths = (async () => {
5+
const posts = [
6+
{ slug: 'one', data: {draft: false, title: 'One'} },
7+
{ slug: 'two', data: {draft: false, title: 'Two'} }
8+
];
9+
return posts.map((post) => {
10+
return {
11+
params: { slug: post.slug },
12+
props: { draft: post.data.draft, title: post.data.title },
13+
};
14+
});
15+
})
16+
17+
const { slug } = Astro.params;
18+
const { title } = Astro.props;
19+
---
20+
<html>
21+
<head>
22+
<title>{ title }</title>
23+
</head>
24+
<body>
25+
<h1>{ title }</h1>
26+
</body>
27+
</html>

packages/integrations/netlify/test/functions/redirects.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ describe('SSG - Redirects', () => {
88

99
before(async () => {
1010
fixture = await loadFixture({
11-
root: new URL('../static/fixtures/redirects/', import.meta.url).toString(),
12-
output: 'server',
11+
root: new URL('../functions/fixtures/redirects/', import.meta.url).toString(),
12+
output: 'hybrid',
1313
adapter: netlifyAdapter({
14-
dist: new URL('../static/fixtures/redirects/dist/', import.meta.url),
14+
dist: new URL('../functions/fixtures/redirects/dist/', import.meta.url),
1515
}),
1616
site: `http://example.com`,
1717
integrations: [testIntegration()],
@@ -45,4 +45,13 @@ describe('SSG - Redirects', () => {
4545
]);
4646
expect(redirects).to.matchSnapshot();
4747
});
48+
49+
it('Does not create .html files', async () => {
50+
try {
51+
await fixture.readFile('/other/index.html');
52+
expect(false).to.equal(true, 'this file should not exist');
53+
} catch {
54+
expect(true).to.equal(true);
55+
}
56+
});
4857
});

0 commit comments

Comments
 (0)