Micro LiveReload Server
Micro Live Reload server is a websocket server which delivers a message whenever
notifyReload server instance method is called; the only purpose of it is as a development tool.
NOTE: My aim to build this server was because I faced a problem with common tiny-lr server which implements LiveReload wide extended live reload protocol and gulp-livereload and after I spent some hours figuring out the issue and I couldn't find it, I developed it and later on, I found a workaround, therefore I discourage to use it as a replacement of any LiveReload implementation and the implementation will remain here as historical documentation.
Be aware that its project is not currently maintained
It is a module which exports a Server class method whose instances wrap a websocket server built with engine.io that allows to send a websocket message (client side must use engine.io-client which a basic implementation of a browserify module is delivered by this server) each time that
notifyReload of a server instances is called.
When the provided client side script for this server is used, it basically reloads the page calling in the browser
window.location.reload(), without any other secret.
npm install u-lr
The module export a Server class method whose constructor accept an options object which is provided straightaway to attach of an instance of engine.io#Server, with only one optional parameter more,
port, which is the port number to use by the HTTP Server and by default, it listens on 49000.
Each Server instance has three methods:
All of them, only receive one parameter, a
callback function, which is called with an
error object if it something goes wrong, the well-known callback node convention.
stop are self-explained.
notifyReload is used to notify to server to send a websocket message to warn to the connected socket clients to reload the page.
The client side must be a engine.io-client which listens messages (
message event) which receive a data packet with a JSON object always with this values:
message: 'reload'data:type: '*'
The message content is not significant, because it only delivers one message and always with the same value, but I thought to use it, than an empty message, to easy backward compatibility if in some point I decided to extend it.
The server is a HTTP server with only has one route
/require-module, any other request, it will send back a response with status code
501 Not Implemented.
require function definition; this module can be required using
require('u-lr'), which exports a function that receives one optional parameters, an object with this options:
- host: The host where the server is listening, by default
- port: The port where the server is listening, by default
When the exported function is called, a client websocket connection is stablished and a
message event listener is registered, which reload the page whenever a message is received.
Just MIT, read LICENSE file for more information.