mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2026-01-12 01:59:14 +00:00
refactor: change signature for passthrough function
This commit is contained in:
5
sw.js
5
sw.js
@@ -1,4 +1,4 @@
|
|||||||
function registerWasmHTTPListener(wasm, { base, cacheName, passthroughFunc, args = [] } = {}) {
|
function registerWasmHTTPListener(wasm, { base, cacheName, passthrough, args = [] } = {}) {
|
||||||
let path = new URL(registration.scope).pathname
|
let path = new URL(registration.scope).pathname
|
||||||
if (base && base !== '') path = `${trimEnd(path, '/')}/${trimStart(base, '/')}`
|
if (base && base !== '') path = `${trimEnd(path, '/')}/${trimStart(base, '/')}`
|
||||||
|
|
||||||
@@ -17,10 +17,11 @@ function registerWasmHTTPListener(wasm, { base, cacheName, passthroughFunc, args
|
|||||||
WebAssembly.instantiateStreaming(source, go.importObject).then(({ instance }) => go.run(instance))
|
WebAssembly.instantiateStreaming(source, go.importObject).then(({ instance }) => go.run(instance))
|
||||||
|
|
||||||
addEventListener('fetch', e => {
|
addEventListener('fetch', e => {
|
||||||
if (passthroughFunc && passthroughFunc(e.request)) {
|
if (passthrough?.(e.request)) {
|
||||||
e.respondWith(fetch(e.request))
|
e.respondWith(fetch(e.request))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { pathname } = new URL(e.request.url)
|
const { pathname } = new URL(e.request.url)
|
||||||
if (!pathname.startsWith(path)) return
|
if (!pathname.startsWith(path)) return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user