Skip to content

Commit 08f2641

Browse files
rsbhclaude
andauthored
fix: move API markdown route to utils to prevent SSR interception (#79)
The catch-all `apis/[...slug].md.ts` route intercepted all `/apis/**` requests. For non-`.md` paths it returned undefined, which Nitro treated as empty 200, blocking SSR. Moved to a util function called from the root `[...slug].md.ts` handler instead. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent df3f1e3 commit 08f2641

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

packages/chronicle/src/server/routes/[...slug].md.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import matter from 'gray-matter';
33
import { defineHandler, HTTPError } from 'nitro';
44
import { getPage, getOriginalPath } from '@/lib/source';
55
import { safePath } from '@/server/utils/safe-path';
6+
import { handleApiMarkdown } from '@/server/utils/api-markdown';
67

78
export default defineHandler(async event => {
89
const pathname = event.path || event.req.url?.split('?')[0] || '';
910
if (!pathname.endsWith('.md')) return;
10-
if (pathname.startsWith('/apis/')) return;
11+
12+
if (pathname.startsWith('/apis/')) {
13+
return handleApiMarkdown(pathname);
14+
}
1115

1216
const stripped = pathname.replace(/\.md$/, '');
1317
const parts = stripped === '/index' || stripped === '/'

packages/chronicle/src/server/routes/apis/[...slug].md.ts renamed to packages/chronicle/src/server/utils/api-markdown.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import type { OpenAPIV3 } from 'openapi-types'
2-
import { defineHandler, HTTPError } from 'nitro'
2+
import { HTTPError } from 'nitro'
33
import { loadConfig } from '@/lib/config'
44
import { loadApiSpecs } from '@/lib/openapi'
55
import { findApiOperation } from '@/lib/api-routes'
66
import { flattenSchema, generateExampleJson, type SchemaField } from '@/lib/schema'
77
import { generateCurl } from '@/lib/snippet-generators'
88

9-
export default defineHandler(async event => {
10-
const pathname = event.path || event.req.url?.split('?')[0] || ''
11-
if (!pathname.endsWith('.md')) return
12-
9+
export async function handleApiMarkdown(pathname: string) {
1310
const stripped = pathname.replace(/\.md$/, '').replace(/^\/apis\//, '')
1411
const slug = stripped.split('/').filter(Boolean)
1512
if (slug.length < 2) {
@@ -26,7 +23,7 @@ export default defineHandler(async event => {
2623

2724
const md = generateApiMarkdown(match.method, match.path, match.operation, match.spec.server.url, match.spec.auth)
2825
return new Response(md, { headers: { 'Content-Type': 'text/markdown; charset=utf-8' } })
29-
})
26+
}
3027

3128
function generateApiMarkdown(
3229
method: string,

0 commit comments

Comments
 (0)