const {h, render, Component} = preact; const html = htm.bind(h); const Info = () => html`
This dashboard shows values kept in server memory. Many clients can open this page. As soon as any client changes any value, all clients update automatically.

The JS code that watches state changes, reconnects on network failures. That means if server restarts, dashboard on all connected clients refresh automatically.

You can use curl command-line utility:
curl localhost:8000/api/config/get
curl localhost:8000/api/config/watch
curl localhost:8000/api/config/set -d '{"a":123}'
`; class Dashboard extends Component { state = {value1: null, value2: null}; componentDidMount() { axios.get('/api/config/get') .then(r => this.setState(r.data)) .catch(e => console.log(e)); var self = this; var f = function(reader) { return reader.read().then(function(result) { var data = String.fromCharCode.apply(null, result.value); self.setState(JSON.parse(data)); // console.log(JSON.parse(data)); if (!result.done) return f(reader); }); }; fetch('/api/config/watch') .then(r => r.body.getReader()) .then(f) .catch(e => setTimeout(x => self.componentDidMount(), 1000)); } render(props, state) { return html `
Value 1 (number):
${state.value1}
Value 2 (string):
${state.value2}
` } }; class Form extends Component { render(props, state) { const onclick = ev => axios.post( '/api/config/set', {value1: +state.value1, value2: state.value2}); // alert(JSON.stringify(state)); return html`
Change values
Value 1 (number):
Value 2 (string):
` } }; const App = () => html`
<${Info} /> <${Dashboard} /> <${Form} />
`; window.onload = () => render(h(App), document.body);