Prevent building .html files in hybrid mode (#7805)
* Prevent building .html files in hybrid mode * Adding a changeset
This commit is contained in:
parent
db8c04002f
commit
42a21b5da6
6 changed files with 57 additions and 3 deletions
5
.changeset/ninety-kids-fail.md
Normal file
5
.changeset/ninety-kids-fail.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/netlify': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Prevent building .html file redirects in hybrid mode
|
|
@ -40,6 +40,7 @@ function netlifyFunctions({
|
||||||
updateConfig({
|
updateConfig({
|
||||||
outDir,
|
outDir,
|
||||||
build: {
|
build: {
|
||||||
|
redirects: false,
|
||||||
client: outDir,
|
client: outDir,
|
||||||
server: new URL('./.netlify/functions-internal/', config.root),
|
server: new URL('./.netlify/functions-internal/', config.root),
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
export const prerender = false;
|
||||||
|
---
|
||||||
|
<html>
|
||||||
|
<head><title>Testing</title></head>
|
||||||
|
<body>
|
||||||
|
<h1>Testing</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
return Astro.redirect('/');
|
||||||
|
---
|
|
@ -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;
|
||||||
|
---
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{ title }</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>{ title }</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -8,10 +8,10 @@ describe('SSG - Redirects', () => {
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: new URL('../static/fixtures/redirects/', import.meta.url).toString(),
|
root: new URL('../functions/fixtures/redirects/', import.meta.url).toString(),
|
||||||
output: 'server',
|
output: 'hybrid',
|
||||||
adapter: netlifyAdapter({
|
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`,
|
site: `http://example.com`,
|
||||||
integrations: [testIntegration()],
|
integrations: [testIntegration()],
|
||||||
|
@ -45,4 +45,13 @@ describe('SSG - Redirects', () => {
|
||||||
]);
|
]);
|
||||||
expect(redirects).to.matchSnapshot();
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue