mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +00:00
20 lines
493 B
TypeScript
20 lines
493 B
TypeScript
import { defineLazyHandler } from 'h3'
|
|
|
|
export default defineLazyHandler(async () => {
|
|
const { exports: { sum } } = await loadWasmInstance(
|
|
// @ts-ignore
|
|
() => 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
|
|
}
|