23 lines
586 B
JavaScript
23 lines
586 B
JavaScript
|
/**
|
||
|
* This script polls /__hotreload__ and reloads the page if the response changes.
|
||
|
*/
|
||
|
|
||
|
|
||
|
// TODO: get commit from environment
|
||
|
const commit = "000000"
|
||
|
|
||
|
console.log(`running ${commit} in development mode`)
|
||
|
|
||
|
async function fetchStatus() {
|
||
|
const r = await fetch("/__hotreload__", { cache: "no-cache" })
|
||
|
return await r.text()
|
||
|
}
|
||
|
|
||
|
async function hotreload() {
|
||
|
const status = await fetchStatus()
|
||
|
setInterval(async () => {
|
||
|
const newStatus = await fetchStatus()
|
||
|
if (status !== newStatus) window.location.reload()
|
||
|
}, 1_000)
|
||
|
}
|
||
|
hotreload().catch(console.error)
|