Skip to content

Commit e863443

Browse files
committed
docs(templates): add server route
1 parent 8c73cf1 commit e863443

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/server/api/templates.json.get.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { handleCors } from 'h3'
2+
3+
export default defineEventHandler(async (event) => {
4+
const didHandleCors = handleCors(event, {
5+
origin: ['https://nuxt.studio', 'https://dev.nuxt.studio'],
6+
preflight: {
7+
statusCode: 204,
8+
},
9+
methods: '*',
10+
})
11+
12+
if (didHandleCors) {
13+
return
14+
}
15+
16+
const templates = await queryCollection(event, 'templates').all()
17+
18+
if (!templates) {
19+
throw createError({
20+
statusCode: 404,
21+
statusMessage: 'Templates not found',
22+
})
23+
}
24+
25+
return templates
26+
})

0 commit comments

Comments
 (0)