This commit is contained in:
Nicolas Lepage 2021-01-24 21:52:41 +01:00
parent ce9bfc89b8
commit 79db7567a5
No known key found for this signature in database
GPG Key ID: B0879E35E66D8F6F
3 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>go-wasm-http-server hello with state demo</title>
<script>
navigator.serviceWorker.register('sw.js').then(registration => {
const sw = registration.active ?? registration.installing ?? registration.waiting
setInterval(() => sw.postMessage(null), 15000)
})
async function hello() {
res = await fetch('api/hello', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: document.querySelector("#name").value })
})
const { message } = await res.json()
alert(message)
}
</script>
</head>
<body>
<label for="name">Name: </label><input id="name" value="World">
<button onclick="hello()">Hello</button>
</body>
</html>

View File

@ -0,0 +1,13 @@
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@078ff3547ebe2abfbee1fd5af9ca5ad64be480c0/sw.js')
addEventListener('install', event => {
event.waitUntil(skipWaiting())
})
addEventListener('activate', event => {
event.waitUntil(clients.claim())
})
addEventListener('message', () => {})
registerWasmHTTPListener('../hello-state/api.wasm', { base: 'api' })

View File

@ -7,6 +7,7 @@
<ul>
<li><a href="hello">Hello demo</a> (<a href="https://github.com/nlepage/go-wasm-http-server/tree/master/docs/hello">sources</a>)</li>
<li><a href="hello-state">Hello with state demo</a> (<a href="https://github.com/nlepage/go-wasm-http-server/tree/master/docs/hello-state">sources</a>)</li>
<li><a href="hello-state-keepalive">Hello with state and keepalive demo</a> (<a href="https://github.com/nlepage/go-wasm-http-server/tree/master/docs/hello-state-keepalive">sources</a>)</li>
<li><a href="https://nlepage.github.io/catption/wasm/">😺 Catption generator demo</a> (<a href="https://github.com/nlepage/catption/tree/wasm">sources</a>)</li>
</ul>
</body>