diff --git a/build-output-api/on-demand-isr/.vercel/output/config.json b/build-output-api/on-demand-isr/.vercel/output/config.json index cd2f236b29..e4ea072deb 100644 --- a/build-output-api/on-demand-isr/.vercel/output/config.json +++ b/build-output-api/on-demand-isr/.vercel/output/config.json @@ -1,3 +1,10 @@ { - "version": 3 + "version": 3, + "routes": [ + { "handle": "filesystem" }, + { + "src": "/blog/(?[^/]+)(?:/)?", + "dest": "/blog/[slug]?slug=$slug" + } + ] } diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/blog/404.prerender-fallback.html b/build-output-api/on-demand-isr/.vercel/output/functions/blog/404.prerender-fallback.html new file mode 100644 index 0000000000..a89b98806d --- /dev/null +++ b/build-output-api/on-demand-isr/.vercel/output/functions/blog/404.prerender-fallback.html @@ -0,0 +1,13 @@ + + + + 404 | Not Found + + +

Not Found

+ + +

Generate this path via On-Demand ISR

+ + + \ No newline at end of file diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].func/.vc-config.json b/build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].func/.vc-config.json new file mode 100644 index 0000000000..f0611dc75b --- /dev/null +++ b/build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].func/.vc-config.json @@ -0,0 +1,5 @@ +{ + "runtime": "nodejs16.x", + "handler": "index.js", + "launcherType": "Nodejs" +} diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].func/index.js b/build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].func/index.js new file mode 100644 index 0000000000..12e81c8f37 --- /dev/null +++ b/build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].func/index.js @@ -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(` + + + + My blog | ${slug} + + +

Post: ${slug}

+

Generated time: ${new Date().toISOString()}

+ +

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.

+ +

It works by leveraging \`expiration: false\` on a prerender to only allow generating new paths when the revalidate token is provided.

+ + +

Revalidate this path via On-Demand ISR

+ + + `) +} diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].prerender-config.json b/build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].prerender-config.json new file mode 100644 index 0000000000..77ba0c71b5 --- /dev/null +++ b/build-output-api/on-demand-isr/.vercel/output/functions/blog/[slug].prerender-config.json @@ -0,0 +1,7 @@ +{ + "expiration": false, + "group": 3, + "bypassToken": "87734ad8259d67c3c11747d3e4e112d0", + "allowQuery": ["slug"], + "fallback": "404.prerender-fallback.html" +} diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.func b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.func new file mode 120000 index 0000000000..b25d36febb --- /dev/null +++ b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.func @@ -0,0 +1 @@ +[slug].func \ No newline at end of file diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.prerender-config.json b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.prerender-config.json new file mode 100644 index 0000000000..beac692291 --- /dev/null +++ b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.prerender-config.json @@ -0,0 +1,7 @@ +{ + "expiration": false, + "group": 3, + "bypassToken": "87734ad8259d67c3c11747d3e4e112d0", + "allowQuery": ["slug"], + "fallback": "post-1.prerender-fallback.html" +} diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.prerender-fallback.html b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.prerender-fallback.html new file mode 100644 index 0000000000..ce3d00583c --- /dev/null +++ b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-1.prerender-fallback.html @@ -0,0 +1,17 @@ + + + + My blog | post-1 + + +

Post: post-1

+

Generated time: 2022-08-11T15:12:34.656Z

+ +

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.

+ +

It works by leveraging `expiration: false` on a prerender to only allow generating new paths when the revalidate token is provided.

+ + +

Revalidate this path via On-Demand ISR

+ + diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.func b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.func new file mode 120000 index 0000000000..b25d36febb --- /dev/null +++ b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.func @@ -0,0 +1 @@ +[slug].func \ No newline at end of file diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.prerender-config.json b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.prerender-config.json new file mode 100644 index 0000000000..fab0f1d051 --- /dev/null +++ b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.prerender-config.json @@ -0,0 +1,7 @@ +{ + "expiration": false, + "group": 3, + "bypassToken": "87734ad8259d67c3c11747d3e4e112d0", + "allowQuery": ["slug"], + "fallback": "post-2.prerender-fallback.html" +} diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.prerender-fallback.html b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.prerender-fallback.html new file mode 100644 index 0000000000..a30ba1a08f --- /dev/null +++ b/build-output-api/on-demand-isr/.vercel/output/functions/blog/post-2.prerender-fallback.html @@ -0,0 +1,17 @@ + + + + My blog | post-2 + + +

Post: post-2

+

Generated time: 2022-08-11T15:12:34.656Z

+ +

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.

+ +

It works by leveraging `expiration: false` on a prerender to only allow generating new paths when the revalidate token is provided.

+ + +

Revalidate this path via On-Demand ISR

+ + diff --git a/build-output-api/on-demand-isr/.vercel/output/functions/revalidate.func/index.js b/build-output-api/on-demand-isr/.vercel/output/functions/revalidate.func/index.js index 23330111df..6c22767686 100644 --- a/build-output-api/on-demand-isr/.vercel/output/functions/revalidate.func/index.js +++ b/build-output-api/on-demand-isr/.vercel/output/functions/revalidate.func/index.js @@ -60,7 +60,7 @@ module.exports = (req, res) => { res.end(`

Cache for "${pathToRevalidate}" Revalidated!

Redirecting you back.

- + `) }).catch((error) => { console.error(error.stack) diff --git a/build-output-api/on-demand-isr/README.md b/build-output-api/on-demand-isr/README.md index be9a732d72..1f3c6c698c 100644 --- a/build-output-api/on-demand-isr/README.md +++ b/build-output-api/on-demand-isr/README.md @@ -33,6 +33,16 @@ In this demo, you can see this happening with two paths: `/` and `/data`. When the revalidation is triggered, the cache will be revalidated, bypassing any caching that Vercel would normally provide. +There is also an example of a blog that only generates new paths when triggered via On-Demand ISR with two initial posts that are prerendered. + +- `/blog/[slug]` + - base post prerender that allows generating news paths via On-Demand ISR + - [bypassToken](./.vercel/output/functions/index.prerender-config.json#L4) +- `/blog/post-1` +- `/blog/post-2` + - initial prerendered blog posts + - [bypassToken](./.vercel/output/functions/index.prerender-config.json#L4) + ### Security #### `bypassToken`