mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +00:00
20 lines
557 B
TypeScript
20 lines
557 B
TypeScript
import { defineLazyEventHandler } from 'h3'
|
|
|
|
export default defineLazyEventHandler(async () => {
|
|
const { exports: { sum } } = await loadWasmInstance(
|
|
// @ts-expect-error TODO: https://github.com/nuxt/nuxt/issues/14131
|
|
() => import('~/server/wasm/sum.wasm')
|
|
)
|
|
|
|
return (event) => {
|
|
const { a = 0, b = 0 } = getQuery(event)
|
|
return { sum: sum(a, b) }
|
|
}
|
|
})
|
|
|
|
async function loadWasmInstance (importFn, imports = {}) {
|
|
const init = await importFn().then(m => m.default || m)
|
|
const { instance } = await init(imports)
|
|
return instance
|
|
}
|