-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support prerender in Netlify redirects (#5904)
* Support prerender in Netlify redirects * Updated sorting algorithm * Update packages/integrations/netlify/src/shared.ts Co-authored-by: Bjorn Lu <[email protected]> Co-authored-by: Bjorn Lu <[email protected]>
- Loading branch information
Showing
12 changed files
with
240 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/netlify': patch | ||
--- | ||
|
||
Support prerender in \_redirects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ges/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/[cat].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
export const prerender = true | ||
export function getStaticPaths() { | ||
return [ | ||
{ | ||
params: {cat: 'cat1'}, | ||
props: {cat: 'cat1'} | ||
}, | ||
{ | ||
params: {cat: 'cat2'}, | ||
props: {cat: 'cat2'} | ||
}, | ||
{ | ||
params: {cat: 'cat3'}, | ||
props: {cat: 'cat3'} | ||
}, | ||
]; | ||
} | ||
const { cat } = Astro.props; | ||
--- | ||
|
||
<div>Good cat, {cat}!</div> | ||
|
||
<a href="/">back</a> |
27 changes: 27 additions & 0 deletions
27
...ges/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/[dog].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
export const prerender = true | ||
export function getStaticPaths() { | ||
return [ | ||
{ | ||
params: {dog: 'dog1'}, | ||
props: {dog: 'dog1'} | ||
}, | ||
{ | ||
params: {dog: 'dog2'}, | ||
props: {dog: 'dog2'} | ||
}, | ||
{ | ||
params: {dog: 'dog3'}, | ||
props: {dog: 'dog3'} | ||
}, | ||
]; | ||
} | ||
const { dog } = Astro.props; | ||
--- | ||
|
||
<div>Good dog, {dog}!</div> | ||
|
||
<a href="/">back</a> |
12 changes: 12 additions & 0 deletions
12
...ges/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<meta name="generator" content={Astro.generator} /> | ||
<title>Astro</title> | ||
</head> | ||
<body> | ||
<h1>Astro</h1> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/404.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
</head> | ||
<body> | ||
<h1>testing</h1> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
</head> | ||
<body> | ||
<h1>testing</h1> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/one.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
export const prerender = true; | ||
--- | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
</head> | ||
<body> | ||
<h1>testing</h1> | ||
</body> | ||
</html> |
30 changes: 30 additions & 0 deletions
30
packages/integrations/netlify/test/functions/prerender.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect } from 'chai'; | ||
import netlifyAdapter from '../../dist/index.js'; | ||
import { loadFixture, testIntegration } from './test-utils.js'; | ||
|
||
describe('Mixed Prerendering with SSR', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: new URL('./fixtures/prerender/', import.meta.url).toString(), | ||
output: 'server', | ||
adapter: netlifyAdapter({ | ||
dist: new URL('./fixtures/prerender/dist/', import.meta.url), | ||
}), | ||
site: `http://example.com`, | ||
integrations: [testIntegration()], | ||
}); | ||
await fixture.build(); | ||
}); | ||
it('Wildcard 404 is sorted last', async () => { | ||
const redir = await fixture.readFile('/_redirects'); | ||
const baseRouteIndex = redir.indexOf('/ /.netlify/functions/entry 200'); | ||
const oneRouteIndex = redir.indexOf('/one /one/index.html 200'); | ||
const fourOhFourWildCardIndex = redir.indexOf('/* /.netlify/functions/entry 404'); | ||
|
||
expect(fourOhFourWildCardIndex).to.be.greaterThan(baseRouteIndex); | ||
expect(fourOhFourWildCardIndex).to.be.greaterThan(oneRouteIndex); | ||
}); | ||
}); |