lastwebnovel-app/server/api/novels/[id].ts
2026-04-11 22:55:16 +02:00

18 lines
444 B
TypeScript

import type { WebNovel } from '~/types'
export default defineEventHandler(async (event): Promise<WebNovel | null> => {
const id = getRouterParam(event, 'id')
const novels = await queryCollection('content').all() as WebNovel[]
const novel = novels.find(n => n._path === `/novels/${id}` || n.slug === id)
if (!novel) {
throw createError({
statusCode: 404,
statusMessage: 'Novel not found'
})
}
return novel
})