Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/markdown-not-found.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const body = `# Page not found

This URL does not match a page in the Temporal documentation.

## Where to look next

- [Documentation index](https://docs.temporal.io/llms.txt)
- [Documentation sitemap](https://docs.temporal.io/sitemap.xml)
- [Temporal documentation home](https://docs.temporal.io/)
`;

module.exports = (_request, response) => {
response
.status(404)
.setHeader('Content-Type', 'text/markdown; charset=utf-8')
.setHeader('Vary', 'Accept, Accept-Encoding')
.send(body);
};
5 changes: 3 additions & 2 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { rewrite, next } from '@vercel/functions';

export default function middleware(request) {
const accept = request.headers.get('accept') || '';
const headers = { Vary: 'Accept, Accept-Encoding' };

if (accept.includes('text/markdown')) {
const url = new URL(request.url);
const path = url.pathname.replace(/\/+$/, '') || '/index';
return rewrite(new URL(`${path}.md`, request.url));
return rewrite(new URL(`${path}.md`, request.url), { headers });
}

return next();
return next({ headers });
}

export const config = {
Expand Down
11 changes: 11 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
{
"source": "/img/og/:path*",
"destination": "/img/assets/open-graph-shiny.jpg"
},
{
"source": "/:path((?!api/).*)",
"has": [
{
"type": "header",
"key": "accept",
"value": ".*text/markdown.*"
}
],
"destination": "/api/markdown-not-found"
}
],
"headers": [
Expand Down