Comparing version 0.3.0 to 0.4.0
@@ -0,1 +1,6 @@ | ||
0.4.0 / 2015-08-17 | ||
------------------ | ||
- add `true` option to `delay` so that it weights indefinitely until server is up https://github.com/jprichardson/reload/pull/21 | ||
- express 4 routes, https://github.com/jprichardson/reload/pull/24 | ||
0.3.0 / 2015-07-17 | ||
@@ -2,0 +7,0 @@ ------------------ |
;(function refresh () { | ||
var RLD_TIMEOUT = 300; | ||
var sock = new SockJS(window.location.origin + '/sockreload'); | ||
var waitForServer = false; | ||
var sock; | ||
var checkDelay = 1; | ||
var checkDelayCounter = 1; | ||
sock.onclose = function() { | ||
setTimeout(function() { | ||
var newConn = function() { | ||
//try and connect a new socket to the server. | ||
sock = new SockJS(window.location.origin + '/sockreload'); | ||
//if the server is up then, the sockert will reach this event handler and then call refreshPage | ||
sock.onopen = function() { | ||
window.location.reload(); | ||
},RLD_TIMEOUT); | ||
}; | ||
//else the server is down try and connect again with another call to newConn | ||
//this will exponentially increase the wait time to slow down the calls to checkServerUp to prevent this script from spamming requests if the server doesn’t come back up quickly. | ||
//this is useful in the case when the user brings down the server but forgets to close their dev tab or a server has a long restart time. | ||
checkDelay = (Math.pow(checkDelayCounter,6)) / 10000000000; | ||
checkDelayCounter++; | ||
setTimeout(function () { | ||
newConn(); | ||
}, checkDelay); | ||
}; | ||
})(); | ||
sock.onclose = function() { | ||
//check for the server only if the user entered in true for a delay | ||
if (waitForServer) { | ||
sock = null; | ||
newConn(); | ||
} | ||
//else use the default delay or user specified delay | ||
else { | ||
setTimeout(function() { | ||
window.location.reload(); | ||
},RLD_TIMEOUT); | ||
} | ||
}; | ||
})(); |
@@ -17,8 +17,7 @@ var express = require('express') | ||
var router = express.Router(); | ||
app.set('port', port) | ||
app.use(express.static(dir)) //should cache static assets | ||
app.get('/', function(req, res) { | ||
router.get('/', function(req, res, next) { | ||
var startFile = path.join(dir, startPage) | ||
@@ -33,3 +32,3 @@ fs.exists(startFile, function(itDoes) { | ||
app.get('*.html', function(req, res) { | ||
router.get('*.html', function(req, res) { | ||
//this wouldn't be efficient in any other context | ||
@@ -40,2 +39,7 @@ var file = path.join(dir, req.url) | ||
app.use('/', router); | ||
app.use('*html', router); | ||
app.use(express.static(dir)) //should cache static assets | ||
var server = http.createServer(app) | ||
@@ -45,3 +49,2 @@ reload(server, app, delay) | ||
server.listen(app.get('port'), function(){ | ||
if (!fs.existsSync(runFile)) { | ||
@@ -54,3 +57,2 @@ fs.writeFile(runFile, '') | ||
} | ||
}) | ||
@@ -57,0 +59,0 @@ |
@@ -8,3 +8,3 @@ var sockjs = require('sockjs') | ||
module.exports = function reload (httpServer, expressApp, time_ms) { | ||
module.exports = function reload (httpServer, expressApp, delay) { | ||
//this happens at startup of program, so sync is alright | ||
@@ -14,5 +14,9 @@ var sockjsCode = fs.readFileSync(SOCKJS_FILE, 'utf8') | ||
if (time_ms) { | ||
reloadCode = reloadCode.replace('RLD_TIMEOUT = 300', 'RLD_TIMEOUT = ' + time_ms) | ||
// If delay is specified as true then reload will wait for the server to be up before reloading the page | ||
if (delay === true) { | ||
reloadCode = reloadCode.replace('waitForServer = false;', 'waitForServer = true;') | ||
} | ||
else if (delay > 0) { | ||
reloadCode = reloadCode.replace('RLD_TIMEOUT = 300', 'RLD_TIMEOUT = ' + delay) | ||
} | ||
@@ -19,0 +23,0 @@ var clientCode = sockjsCode + '\n\n' + reloadCode |
{ | ||
"name": "reload", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Node.js module to refresh and reload your code in your browser when your code changes. No browser plugins required.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -62,3 +62,4 @@ reload | ||
//reload code here | ||
//reload code here | ||
//optional server delay argument can be given to reload, refer to API below | ||
reload(server, app) | ||
@@ -102,2 +103,3 @@ | ||
//reload code here | ||
//optional server delay argument can be given to reload, refer to API below | ||
reload(server, app) | ||
@@ -150,2 +152,3 @@ | ||
-h, --help Output usage information | ||
@@ -157,5 +160,6 @@ -V, --version Output the version number | ||
-p, --port [port] The port to bind to. Can be set with PORT env variable as well. Defaults to 8080 | ||
-t, --time [delay] How long (ms) should the browser wait before reconnecting? Defaults to 300 ms. | ||
-d, --delay [delay] How long (ms) should the browser wait before reconnecting? You can also specify true, if you would like reload to wait until the server comes back up before reloading the page. Defaults to 300 ms. | ||
-s, --start-page [start-page] Specify a start page. Defaults to index.html. | ||
``` | ||
@@ -181,7 +185,7 @@ | ||
### reload(httpServer, expressApp, [timeout_millis]) | ||
### reload(httpServer, expressApp, [delay]) | ||
- `httpServer`: The Node.js http server from the module `http`. | ||
- `expressApp`: The express app. It may work with other frameworks, or even with Connect. At this time, it's only been tested with Express. | ||
- `timeout_millis`: The client side refresh time in milliseconds. Default is `300`. | ||
- `delay`: The client side refresh time in milliseconds. Default is `300`. You can also specify true, if you would like reload to wait until the server comes back up before reloading the page. | ||
@@ -188,0 +192,0 @@ |
Sorry, the diff of this file is not supported yet
44888
131
197