Skip to content

Commit

Permalink
Ends client connections on exit and adds reconnect logic (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukejacksonn authored Feb 11, 2020
1 parent 11b31b5 commit 4afcb41
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion servor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const mimes = Object.entries(require('./types.json')).reduce(
const livereload = `
<script>
const source = new EventSource('/livereload');
source.onmessage = e => location.reload(true);
const reload = () => location.reload(true);
source.onmessage = reload;
source.onerror = () => (source.onopen = reload);
console.log('[servor] listening for file changes');
</script>
`;
Expand Down Expand Up @@ -137,6 +139,11 @@ module.exports = async ({
sendMessage(clients.pop(), 'message', 'reload');
});

process.on('SIGINT', () => {
while (clients.length > 0) clients.pop().end();
process.exit();
});

return {
url: `${protocol}://localhost:${port}`,
root,
Expand Down

0 comments on commit 4afcb41

Please sign in to comment.