mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2025-03-10 17:29:10 +00:00
41 lines
1.1 KiB
HTML
41 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>go-wasm-http-server demo</title>
|
|
<script>
|
|
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>
|
|
<script>
|
|
const startWasm = async (wasm, { scope, base = '' } = {}) => {
|
|
try {
|
|
const options = {}
|
|
if (scope) options.scope = scope
|
|
const registration = await navigator.serviceWorker.register('sw.js', options)
|
|
await navigator.serviceWorker.ready
|
|
registration.active.postMessage({
|
|
type: 'startWasm',
|
|
wasm,
|
|
base,
|
|
})
|
|
} catch (e) {
|
|
console.error(e)
|
|
}
|
|
}
|
|
startWasm('api.wasm')
|
|
</script>
|
|
</body>
|
|
</html> |