This repository has been archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add support for preview mode of pre-rendered pages using getStaticProps * remove README caveat * Add Cypress tests: Optional catch-all route at root-level Test that prerendered pages and static files from /public are correctly served under the redirect engine used with cookie-based redirects when having an optional catch-all route at root-level. * Cleanup: Remove unnecessary require We do not need `existsSync` in the `setupNetlifyFunctionForPage` helper. * miscellaneous finishing touches for ssg preview mode * move preview mode note in readme and update isroutewithfallback helper Co-authored-by: Finn Woelm <[email protected]>
- Loading branch information
1 parent
2ee0f0d
commit c23aee5
Showing
25 changed files
with
470 additions
and
43 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 |
---|---|---|
|
@@ -39,3 +39,6 @@ jspm_packages | |
|
||
# OS | ||
.DS_Store | ||
|
||
# Local Netlify folder | ||
.netlify |
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
9 changes: 9 additions & 0 deletions
9
cypress/fixtures/pages-with-optionalCatchAll-at-root/[[...slug]].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,9 @@ | ||
const Page = () => <p>root-level optional-catch-all</p>; | ||
|
||
export async function getServerSideProps() { | ||
return { | ||
props: {}, | ||
}; | ||
} | ||
|
||
export default Page; |
9 changes: 9 additions & 0 deletions
9
cypress/fixtures/pages-with-optionalCatchAll-at-root/static.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,9 @@ | ||
const Static = () => <p>static page</p>; | ||
|
||
export async function getStaticProps() { | ||
return { | ||
props: {}, | ||
}; | ||
} | ||
|
||
export default Static; |
27 changes: 27 additions & 0 deletions
27
cypress/fixtures/pages-with-optionalCatchAll-at-root/subfolder/[id].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,27 @@ | ||
const Static = () => <p>static page in subfolder</p>; | ||
|
||
export async function getStaticPaths() { | ||
return { | ||
paths: [ | ||
{ | ||
params: { | ||
id: "static", | ||
}, | ||
}, | ||
{ | ||
params: { | ||
id: "test", | ||
}, | ||
}, | ||
], | ||
fallback: true, | ||
}; | ||
} | ||
|
||
export async function getStaticProps() { | ||
return { | ||
props: {}, | ||
}; | ||
} | ||
|
||
export default Static; |
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 @@ | ||
export default async function preview(req, res) { | ||
const { query } = req; | ||
const { id } = query; | ||
|
||
// Enable Preview Mode by setting the cookies | ||
res.setPreviewData({}); | ||
|
||
// Redirect to the path from the fetched post | ||
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities | ||
res.writeHead(307, { Location: `/previewTest/static` }); | ||
res.end(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Link from "next/link"; | ||
|
||
const StaticTest = ({ number }) => { | ||
return ( | ||
<div> | ||
<p> | ||
This page uses getStaticProps() and is SSRed when in preview mode. | ||
<br /> | ||
<br /> | ||
By default, it shows the TV show by ID (as static HTML). | ||
<br /> | ||
But when in preview mode, it shows person by ID instead (SSRed). | ||
</p> | ||
|
||
<hr /> | ||
|
||
<h1>Number: {number}</h1> | ||
|
||
<Link href="/"> | ||
<a>Go back home</a> | ||
</Link> | ||
</div> | ||
); | ||
}; | ||
|
||
export const getStaticProps = async ({ preview }) => { | ||
let number; | ||
|
||
// In preview mode, use odd number | ||
if (preview) { | ||
number = 3; | ||
} | ||
// In normal mode, use even number | ||
else { | ||
number = 4; | ||
} | ||
|
||
return { | ||
props: { | ||
number, | ||
}, | ||
}; | ||
}; | ||
|
||
export default StaticTest; |
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 @@ | ||
a text file |
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 @@ | ||
a text file in a folder |
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 @@ | ||
a text file in a subfolder |
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
Oops, something went wrong.