Portfolio/server/api/blog/index.get.ts
2026-09-08 19:54:06 +02:00

17 lines
480 B
TypeScript

import { listPosts, listTags } from '~~/server/utils/posts'
export default defineEventHandler(async (event) => {
const { tag } = getQuery(event) as { tag?: string }
try {
const [posts, tags] = await Promise.all([listPosts({ tag }), listTags()])
return { posts, tags }
} catch (error) {
console.error('[api/blog] failed to list posts:', error)
throw createError({
statusCode: 502,
message: 'the content repository is unreachable',
})
}
})