docs(ComponentExample): add

This commit is contained in:
Benjamin Canac
2024-07-11 17:36:50 +02:00
parent 57e62f36c4
commit 96e18ef233
10 changed files with 68 additions and 44 deletions

View File

@@ -0,0 +1,19 @@
import { defineEventHandler, createError, appendHeader } from 'h3'
import { pascalCase } from 'scule'
// @ts-expect-error - no types available
import components from '#component-example/nitro'
export default defineEventHandler((event) => {
appendHeader(event, 'Access-Control-Allow-Origin', '*')
const componentName = (event.context.params['component?'] || '').replace(/\.json$/, '')
if (componentName) {
const component = components[pascalCase(componentName)]
if (!component) {
throw createError({
statusMessage: 'Example not found!',
statusCode: 404
})
}
return component
}
})