mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2025-03-10 17:29:10 +00:00
🔥
This commit is contained in:
parent
574bb8928c
commit
078ff3547e
15
index.js
15
index.js
@ -1,15 +0,0 @@
|
||||
window.wasmhttp = {
|
||||
register: async (wasm, { scope, base = '', swUrl = 'sw.js', args = [] } = {}) => {
|
||||
const options = {}
|
||||
if (scope) options.scope = scope
|
||||
// FIXME register once (beware of changing scope ?)
|
||||
const registration = await navigator.serviceWorker.register(swUrl, options)
|
||||
await navigator.serviceWorker.ready
|
||||
registration.active.postMessage({
|
||||
type: 'wasmhttp.register',
|
||||
wasm,
|
||||
base,
|
||||
args,
|
||||
})
|
||||
}
|
||||
}
|
2
sw.js
2
sw.js
@ -1,6 +1,6 @@
|
||||
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.15.7/misc/wasm/wasm_exec.js')
|
||||
|
||||
function registerWasmHTTPListener(wasm, base, args = []) {
|
||||
function registerWasmHTTPListener(wasm, { base, args = [] } = {}) {
|
||||
let path = new URL(registration.scope).pathname
|
||||
if (base && base !== '') path = `${trimEnd(path, '/')}/${trimStart(base, '/')}`
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user