Skip to content

Commit

Permalink
fix: update h3 usage with explicit defineEventHandler (#1603)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored and farnabaz committed Oct 19, 2022
1 parent 7974cba commit abe3984
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions playground/shared/server/api/parse.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineEventHandler, useBody } from 'h3'
import { defineEventHandler, readBody } from 'h3'
import { parseContent } from '#content/server'

export default defineEventHandler(async (event) => {
const body = await useBody(event)
const body = await readBody(event)

// @ts-ignore
const parsedContent = await parseContent(body.id || 'content:_file.md', body.content)
Expand Down
10 changes: 5 additions & 5 deletions src/runtime/server/api/highlight.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { /* createError, */defineLazyEventHandler, useBody } from 'h3'
import { /* createError, */defineEventHandler, readBody, lazyEventHandler } from 'h3'
import { getHighlighter, BUNDLED_LANGUAGES, BUNDLED_THEMES, Lang, Theme } from 'shiki-es'
import consola from 'consola'
import { HighlightParams, HighlightThemedToken } from '../../types'
Expand Down Expand Up @@ -57,7 +57,7 @@ const resolveBody = (body: Partial<HighlightParams>) => {
}
}

export default defineLazyEventHandler(async () => {
export default lazyEventHandler(async () => {
// Grab highlighter config from publicRuntimeConfig
const { theme, preload } = useRuntimeConfig().content.highlight

Expand Down Expand Up @@ -85,8 +85,8 @@ export default defineLazyEventHandler(async () => {
] as any[]
})

return async (event): Promise<HighlightThemedToken[][]> => {
const params = await useBody<Partial<HighlightParams>>(event)
return defineEventHandler(async (event): Promise<HighlightThemedToken[][]> => {
const params = await readBody<Partial<HighlightParams>>(event)

const { code, lang, theme = { default: highlighter.getTheme() } } = resolveBody(params)

Expand Down Expand Up @@ -142,7 +142,7 @@ export default defineLazyEventHandler(async () => {
}

return highlightedCode
}
})
})

interface HighlightThemedTokenLine {
Expand Down

0 comments on commit abe3984

Please sign in to comment.