-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[build-output-api] Update On-Demand ISR example with expiration: false
prerenders
#374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
{ | ||
"version": 3 | ||
"version": 3, | ||
"routes": [ | ||
{ "handle": "filesystem" }, | ||
{ | ||
"src": "/blog/(?<slug>[^/]+)(?:/)?", | ||
"dest": "/blog/[slug]?slug=$slug" | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
build-output-api/on-demand-isr/.vercel/output/functions/blog/404.prerender-fallback.html
This file contains hidden or 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,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>404 | Not Found</title> | ||
</head> | ||
<body> | ||
<h1>Not Found</h1> | ||
|
||
<!-- Authentication example is for demo purposes only. In a production system, use better authentication strategies. --> | ||
<p><a href="#">Generate this path via On-Demand ISR</a></p> | ||
<script>document.querySelector('a').href = `/revalidate?path=${encodeURIComponent(window.location.pathname)}&authToken=a13f94f6-a441-47ca-95fc-9f44f3450295`</script> | ||
</body> | ||
</html> |
5 changes: 5 additions & 0 deletions
5
build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].func/.vc-config.json
This file contains hidden or 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 @@ | ||
{ | ||
"runtime": "nodejs16.x", | ||
"handler": "index.js", | ||
"launcherType": "Nodejs" | ||
} |
35 changes: 35 additions & 0 deletions
35
build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].func/index.js
This file contains hidden or 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,35 @@ | ||
const { parse } = require('querystring') | ||
|
||
module.exports = (req, res) => { | ||
const matches = parse(req.headers['x-now-route-matches']) | ||
let { slug } = matches | ||
|
||
// if slug isn't present in x-now-route-matches it | ||
// matched at the filesystem level and can be parsed | ||
// from the URL | ||
if (!slug) { | ||
const matches = req.url.match(/\/blog\/([^/]+)(?:\/)?/) | ||
slug = matches[1] | ||
} | ||
|
||
res.setHeader('Content-Type', 'text/html; charset=utf-8') | ||
res.end(` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>My blog | ${slug}</title> | ||
</head> | ||
<body> | ||
<h1>Post: ${slug}</h1> | ||
<p>Generated time: ${new Date().toISOString()}</p> | ||
|
||
<p>This demonstrates a SSG blog that restricts generating new paths via On-Demand ISR instead of allowing any visited paths to generate a new path.</p> | ||
|
||
<p>It works by leveraging \`expiration: false\` on a prerender to only allow generating new paths when the revalidate token is provided.</p> | ||
|
||
<!-- Authentication example is for demo purposes only. In a production system, use better authentication strategies. --> | ||
<p><a href="/revalidate?path=/blog/${slug}&authToken=a13f94f6-a441-47ca-95fc-9f44f3450295">Revalidate this path via On-Demand ISR</a></p> | ||
</body> | ||
</html> | ||
`) | ||
} |
7 changes: 7 additions & 0 deletions
7
build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].prerender-config.json
This file contains hidden or 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,7 @@ | ||
{ | ||
"expiration": false, | ||
"group": 3, | ||
"bypassToken": "87734ad8259d67c3c11747d3e4e112d0", | ||
"allowQuery": ["slug"], | ||
"fallback": "404.prerender-fallback.html" | ||
} |
1 change: 1 addition & 0 deletions
1
build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.func
This file contains hidden or 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 @@ | ||
[slug].func |
7 changes: 7 additions & 0 deletions
7
build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.prerender-config.json
This file contains hidden or 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,7 @@ | ||
{ | ||
"expiration": false, | ||
"group": 3, | ||
"bypassToken": "87734ad8259d67c3c11747d3e4e112d0", | ||
"allowQuery": ["slug"], | ||
"fallback": "post-1.prerender-fallback.html" | ||
} |
17 changes: 17 additions & 0 deletions
17
build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.prerender-fallback.html
This file contains hidden or 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,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>My blog | post-1</title> | ||
</head> | ||
<body> | ||
<h1>Post: post-1</h1> | ||
<p>Generated time: 2022-08-11T15:12:34.656Z</p> | ||
|
||
<p>This demonstrates a SSG blog that restricts generating new paths via On-Demand ISR instead of allowing any visited paths to generate a new path.</p> | ||
|
||
<p>It works by leveraging `expiration: false` on a prerender to only allow generating new paths when the revalidate token is provided.</p> | ||
|
||
<!-- Authentication example is for demo purposes only. In a production system, use better authentication strategies. --> | ||
<p><a href="/revalidate?path=/blog/post-1&authToken=a13f94f6-a441-47ca-95fc-9f44f3450295">Revalidate this path via On-Demand ISR</a></p> | ||
</body> | ||
</html> |
1 change: 1 addition & 0 deletions
1
build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.func
This file contains hidden or 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 @@ | ||
[slug].func |
7 changes: 7 additions & 0 deletions
7
build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.prerender-config.json
This file contains hidden or 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,7 @@ | ||
{ | ||
"expiration": false, | ||
"group": 3, | ||
"bypassToken": "87734ad8259d67c3c11747d3e4e112d0", | ||
"allowQuery": ["slug"], | ||
"fallback": "post-2.prerender-fallback.html" | ||
} |
17 changes: 17 additions & 0 deletions
17
build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.prerender-fallback.html
This file contains hidden or 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,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>My blog | post-2</title> | ||
</head> | ||
<body> | ||
<h1>Post: post-2</h1> | ||
<p>Generated time: 2022-08-11T15:12:34.656Z</p> | ||
|
||
<p>This demonstrates a SSG blog that restricts generating new paths via On-Demand ISR instead of allowing any visited paths to generate a new path.</p> | ||
|
||
<p>It works by leveraging `expiration: false` on a prerender to only allow generating new paths when the revalidate token is provided.</p> | ||
|
||
<!-- Authentication example is for demo purposes only. In a production system, use better authentication strategies. --> | ||
<p><a href="/revalidate?path=/blog/post-2&authToken=a13f94f6-a441-47ca-95fc-9f44f3450295">Revalidate this path via On-Demand ISR</a></p> | ||
</body> | ||
</html> |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an API endpoint to trigger this? Or should we document a
fetch()
call example or something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can add a revalidate endpoint for this similar to the other for clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 1758bd1