mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-12 09:03:53 +00:00
20 lines
485 B
TypeScript
20 lines
485 B
TypeScript
import { useQuery, lazyHandle } from 'h3'
|
|
|
|
export default lazyHandle(async () => {
|
|
const { exports: { sum } } = await loadWasmInstance(
|
|
// @ts-ignore
|
|
() => import('~/server/wasm/sum.wasm')
|
|
)
|
|
|
|
return (req) => {
|
|
const { a = 0, b = 0 } = useQuery(req)
|
|
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
|
|
}
|