mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2025-03-11 01:29:11 +00:00
🚧
This commit is contained in:
parent
ce9bfc89b8
commit
79db7567a5
28
docs/hello-state-keepalive/index.html
Normal file
28
docs/hello-state-keepalive/index.html
Normal 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>
|
13
docs/hello-state-keepalive/sw.js
Normal file
13
docs/hello-state-keepalive/sw.js
Normal 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' })
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user