-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bce2119
commit c098ffa
Showing
5 changed files
with
91 additions
and
34 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 |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
|
||
# exceptions | ||
!.gitkeep | ||
.vercel |
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,32 @@ | ||
import serverConfigs from './server.config.js'; | ||
|
||
const { rewriteRules } = serverConfigs.dev; | ||
|
||
// Exports | ||
// ============================================================================= | ||
export const config = { | ||
matcher: ['/preview/(index.html)?'], | ||
}; | ||
|
||
// Serve virtual /preview/index.html | ||
// Note: See vercel.json for preview routing configuration | ||
// 1. Fetch index.html from /docs/ directory | ||
// 2. Replace CDN URLs with local paths (see rewriteRules) | ||
// 3. Return preview HTML | ||
export default async function middleware(request) { | ||
const { origin } = new URL(request.url); | ||
const indexURL = `${origin}/docs/index.html`; | ||
const indexHTML = await fetch(indexURL).then(res => res.text()); | ||
const previewHTML = rewriteRules.reduce( | ||
(html, rule) => html.replace(rule.match, rule.replace), | ||
indexHTML | ||
); | ||
|
||
return new Response(previewHTML, { | ||
status: 200, | ||
headers: { | ||
'content-type': 'text/html', | ||
'x-robots-tag': 'noindex', | ||
}, | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
{ | ||
"redirects": [ | ||
"headers": [ | ||
{ | ||
"source": "/", | ||
"destination": "./docs/preview.html", | ||
"permanent": true | ||
"source": "/(.*)", | ||
"headers": [{ "key": "x-robots-tag", "value": "noindex" }] | ||
} | ||
], | ||
"redirects": [{ "source": "/", "destination": "/preview/" }], | ||
"rewrites": [ | ||
{ "source": "/preview/CHANGELOG.md", "destination": "/CHANGELOG.md" }, | ||
{ "source": "/preview/:path*", "destination": "/docs/:path*" } | ||
] | ||
} |