Skip to content

Commit 06a90f4

Browse files
fix fetching the apiIndex when running the dev server
1 parent 9bced60 commit 06a90f4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/pages/apiIndex.json.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { APIRoute } from 'astro'
2+
import { getApiIndex } from '../utils/apiIndex/get'
3+
4+
// Prerender at build time so this doesn't run in the Cloudflare Worker
5+
export const prerender = true
6+
7+
export const GET: APIRoute = async () => {
8+
try {
9+
const index = await getApiIndex()
10+
return new Response(JSON.stringify(index), {
11+
status: 200,
12+
headers: {
13+
'Content-Type': 'application/json',
14+
},
15+
})
16+
} catch (error) {
17+
return new Response(
18+
JSON.stringify({ error: 'Failed to load API index' }),
19+
{
20+
status: 500,
21+
headers: {
22+
'Content-Type': 'application/json',
23+
},
24+
}
25+
)
26+
}
27+
}

0 commit comments

Comments
 (0)