mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
1a7b570c82
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
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
|
|
}
|