diff --git a/README.md b/README.md index ab4c54b..57b7ea6 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,8 @@ Create a ServiceWorker file with the following code: 📄 `sw.js` ```js -importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.0.0/sw.js') +importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js') +importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js') registerWasmHTTPListener('path/to/server.wasm') ``` diff --git a/docs/hello-state-keepalive/sw.js b/docs/hello-state-keepalive/sw.js index 2c80d9e..b3d8d6a 100644 --- a/docs/hello-state-keepalive/sw.js +++ b/docs/hello-state-keepalive/sw.js @@ -1,4 +1,5 @@ -importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@078ff3547ebe2abfbee1fd5af9ca5ad64be480c0/sw.js') +importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js') +importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js') addEventListener('install', event => { event.waitUntil(skipWaiting()) diff --git a/docs/hello-state/api.wasm b/docs/hello-state/api.wasm index f331c37..7863ef1 100755 Binary files a/docs/hello-state/api.wasm and b/docs/hello-state/api.wasm differ diff --git a/docs/hello-state/sw.js b/docs/hello-state/sw.js index 686056e..696e874 100644 --- a/docs/hello-state/sw.js +++ b/docs/hello-state/sw.js @@ -1,4 +1,5 @@ -importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.0.0/sw.js') +importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js') +importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js') addEventListener('install', (event) => { event.waitUntil(skipWaiting()) diff --git a/docs/hello/api.wasm b/docs/hello/api.wasm index 5b0b17e..2b20a58 100755 Binary files a/docs/hello/api.wasm and b/docs/hello/api.wasm differ diff --git a/docs/hello/sw.js b/docs/hello/sw.js index 999a0e2..026f6fe 100644 --- a/docs/hello/sw.js +++ b/docs/hello/sw.js @@ -1,4 +1,5 @@ -importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.0.0/sw.js') +importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.18.4/misc/wasm/wasm_exec.js') +importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v1.1.0/sw.js') addEventListener('install', (event) => { event.waitUntil(skipWaiting()) diff --git a/response_recorder.go b/response_recorder.go index fe3e85b..4f2fb40 100644 --- a/response_recorder.go +++ b/response_recorder.go @@ -6,7 +6,7 @@ import ( "syscall/js" ) -// ResponseRecorder extends httptest.ResponseRecorder and implements js.Wrapper +// ResponseRecorder uses httptest.ResponseRecorder to build a JS Response type ResponseRecorder struct { *httptest.ResponseRecorder } @@ -16,10 +16,8 @@ func NewResponseRecorder() ResponseRecorder { return ResponseRecorder{httptest.NewRecorder()} } -var _ js.Wrapper = ResponseRecorder{} - -// JSValue builds and returns the equivalent JS Response (implementing js.Wrapper) -func (rr ResponseRecorder) JSValue() js.Value { +// JSResponse builds and returns the equivalent JS Response +func (rr ResponseRecorder) JSResponse() js.Value { var res = rr.Result() var body js.Value = js.Undefined() diff --git a/serve.go b/serve.go index 323b75a..253588f 100644 --- a/serve.go +++ b/serve.go @@ -45,7 +45,7 @@ func Serve(handler http.Handler) func() { h.ServeHTTP(res, Request(args[0])) - resolve(res) + resolve(res.JSResponse()) }() return resPromise diff --git a/sw.js b/sw.js index 58f6ec1..be99f7d 100644 --- a/sw.js +++ b/sw.js @@ -1,5 +1,3 @@ -importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.15.7/misc/wasm/wasm_exec.js') - function registerWasmHTTPListener(wasm, { base, args = [] } = {}) { let path = new URL(registration.scope).pathname if (base && base !== '') path = `${trimEnd(path, '/')}/${trimStart(base, '/')}`