New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

reload

Package Overview
Dependencies
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reload - npm Package Compare versions

Comparing version 0.7.0 to 0.8.1

.travis.yml

9

CHANGELOG.md

@@ -0,1 +1,10 @@

0.8.1 / 2016-06-05
------------------
- Allow reload from node server. See: https://github.com/jprichardson/reload/pull/38
0.8.0 / 2015-12-21
------------------
- fixed `hostname` flag. See: https://github.com/jprichardson/reload/pull/34
- use `exts` from command line. See: https://github.com/jprichardson/reload/pull/32
0.7.0 / 2015-10-21

@@ -2,0 +11,0 @@ ------------------

78

lib/reload-client.js
;(function refresh () {
var RLD_TIMEOUT = 300;
var sock = new SockJS(window.location.origin + '/sockreload');
var reloadDelay = 300;
var socketDelay = 0;
var wait = false;
var sock;
var checkDelay = 1;
var checkDelayCounter = 1;
/* global SockJS */
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() {
setTimeout(function() {
var sock = new SockJS(window.location.origin + '/sockreload')
var reloadDelay = 300
var socketDelay = 0
var wait = false
var checkDelay = 1
var checkDelayCounter = 1
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 () {
setTimeout(function () {
window.location.reload()
}, socketDelay);
};
//else the server is down try and connect again with another call to newConn
}, socketDelay)
}
//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++;
// 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);
};
newConn()
}, checkDelay)
}
sock.onclose = function() {
//check for the server only if the user entered in true for a delay
sock.onclose = function () {
// check for the server only if the user entered in true for a delay
if (wait) {
sock = null;
sock = null
newConn();
newConn()
} else { // else use the default delay or user specified delay
setTimeout(function () {
window.location.reload()
}, reloadDelay)
}
//else use the default delay or user specified delay
else {
setTimeout(function() {
window.location.reload();
},reloadDelay);
}
sock.onmessage = function (e) {
if (e.data === 'reload') {
sock.onclose()
}
};
})();
}
})()
var express = require('express')
, http = require('http')
, path = require('path')
, reload = require('../lib/reload')
, fs = require('fs')
, open = require('open')
var http = require('http')
var path = require('path')
var reload = require('../lib/reload')
var fs = require('fs')
var open = require('open')

@@ -11,26 +11,24 @@ var app = express()

var port = process.argv[2]
, dir = process.argv[3]
, openBrowser = (process.argv[4] === 'true')
, hostname = process.argv[5]
, runFile = process.argv[6]
, reloadDelay = process.argv[7]
, wait = (process.argv[8] === 'true' ? true : false)
, startPage = process.argv[9]
var dir = process.argv[3]
var openBrowser = (process.argv[4] === 'true')
var hostname = process.argv[5]
var runFile = process.argv[6]
var reloadDelay = process.argv[7]
var wait = (process.argv[8] === 'true')
var startPage = process.argv[9]
var router = express.Router();
var router = express.Router()
app.set('port', port)
router.get('/', function(req, res, next) {
router.get('/', function (req, res, next) {
var startFile = path.join(dir, startPage)
fs.exists(startFile, function(itDoes) {
if (itDoes)
sendhtml(startFile, res)
else
res.status(404).send("Can't find " + startPage);
fs.exists(startFile, function (itDoes) {
if (itDoes) sendhtml(startFile, res)
else res.status(404).send("Can't find " + startPage)
})
})
router.get('*.html', function(req, res) {
//this wouldn't be efficient in any other context
router.get('*.html', function (req, res) {
// this wouldn't be efficient in any other context
var file = path.join(dir, req.url)

@@ -40,6 +38,6 @@ sendhtml(file, res)

app.use('/', router);
app.use('*html', router);
app.use('/', router)
app.use('*html', router)
app.use(express.static(dir)) //should cache static assets
app.use(express.static(dir)) // should cache static assets

@@ -49,7 +47,6 @@ var server = http.createServer(app)

server.listen(app.get('port'), function(){
server.listen(app.get('port'), function () {
if (!fs.existsSync(runFile)) {
fs.writeFile(runFile, '')
if (openBrowser)
open('http://' + hostname + ':' + app.get('port'))
if (openBrowser) open('http://' + hostname + ':' + app.get('port'))
} else {

@@ -61,3 +58,3 @@ console.log(' restarting...')

function sendhtml (file, res) {
fs.readFile(file, 'utf8', function(err, contents) {
fs.readFile(file, 'utf8', function (err, contents) {
if (err) {

@@ -72,2 +69,2 @@ console.error(err)

})
}
}
var sockjs = require('sockjs')
, path = require('path')
, fs = require('fs')
var path = require('path')
var fs = require('fs')
var SOCKJS_FILE = path.join(__dirname, './sockjs-0.3-min.js')
, RELOAD_FILE = path.join(__dirname, './reload-client.js')
var RELOAD_FILE = path.join(__dirname, './reload-client.js')
module.exports = function reload (httpServer, expressApp, reloadDelay, wait) {
//this happens at startup of program, so sync is alright
// this happens at startup of program, so sync is alright
var sockjsCode = fs.readFileSync(SOCKJS_FILE, 'utf8')
, reloadCode = fs.readFileSync(RELOAD_FILE, 'utf8')
var reloadCode = fs.readFileSync(RELOAD_FILE, 'utf8')
var conn
//if reloadDelay is specified as true then reload will wait for the server to be up before reloading the page
// if reloadDelay is specified as true then reload will wait for the server to be up before reloading the page
if (wait === true) {

@@ -18,3 +19,3 @@ reloadCode = reloadCode.replace('wait = false;', 'wait = true;')

}
reloadCode = reloadCode.replace('reloadDelay = 300;', 'reloadDelay = ' + reloadDelay)

@@ -24,9 +25,27 @@

var reload = sockjs.createServer({log: function(){}})
var reload = sockjs.createServer({ log: function () {} })
reload.on('connection', function (connection) {
conn = connection
})
reload.installHandlers(httpServer, {prefix: '/sockreload'})
expressApp.get('/reload/reload.js', function(req, res) {
expressApp.get('/reload/reload.js', function (req, res) {
res.type('text/javascript')
res.send(clientCode)
})
}
return {
'server': reload,
'connection': conn,
'reload': function () {
this.sendMessage('reload')
},
'sendMessage': function (command) {
if (conn) {
conn.write(command)
} else {
console.log('Cannot send "' + command + '" to client: still not connected')
}
}
}
}

@@ -0,0 +0,0 @@ /* SockJS client, version 0.3.4, http://sockjs.org, MIT License

{
"name": "reload",
"version": "0.7.0",
"version": "0.8.1",
"description": "Node.js module to refresh and reload your code in your browser when your code changes. No browser plugins required.",

@@ -17,8 +17,6 @@ "repository": {

"author": "JP Richardson <jprichardson@gmail.com>",
"licenses": [
{
"type": "MIT",
"url": "http://github.com/jprichardson/reload/blob/master/LICENSE"
}
"contributors": [
"Alexander J. Lallier <alexanderlallier@aol.com>"
],
"license": "MIT",
"dependencies": {

@@ -33,10 +31,18 @@ "sockjs": "~0.3.5",

},
"devDependencies": {},
"devDependencies": {
"standard": "^5.4.1"
},
"main": "./lib/reload.js",
"scripts": {
"test": "mocha test"
"standard": "standard",
"test": "npm run standard"
},
"bin": {
"reload": "./bin/reload"
},
"standard": {
"ignore": [
"/lib/sockjs-0.3-min.js"
]
}
}
reload
=======
[![build status](https://api.travis-ci.org/jprichardson/reload.svg)](http://travis-ci.org/jprichardson/reload)
Refresh and reload your code in your browser when your code changes. No browser plugins required. Use with Node.js if you like.

@@ -47,5 +49,5 @@

, logger = require('morgan')
var app = express()
var publicDir = path.join(__dirname, '')

@@ -55,3 +57,3 @@

app.use(logger('dev'))
app.use(bodyParser.json()) //parses json, multi-part (file), url-encoded
app.use(bodyParser.json()) //parses json, multi-part (file), url-encoded

@@ -61,3 +63,3 @@ app.get('/', function(req, res) {

})
var server = http.createServer(app)

@@ -68,3 +70,3 @@

reload(server, app, [reloadDelay], [wait])
server.listen(app.get('port'), function(){

@@ -116,4 +118,4 @@ console.log("Web server listening on port " + app.get('port'));

```html
<!--
watch this: http://www.youtube.com/watch?v=WxmcDoAxdoY
<!--
watch this: http://www.youtube.com/watch?v=WxmcDoAxdoY
-->

@@ -159,3 +161,3 @@ <!doctype html>

-b, --browser Open in the browser automatically.
-h, --hostname If -b flag is being used, this allows for custom hostnames. Defaults to localhost.
-n, --hostname If -b flag is being used, this allows for custom hostnames. Defaults to localhost.
-d, --dir [dir] The directory to serve up. Defaults to current dir.

@@ -184,3 +186,13 @@ -e, --exts [extensions] Extensions separated by commas or pipes. Defaults to html,js,css.

Reload on your terms
---
If you would like to fire the reload event on your own terms you can use fire a reload event by calling `reload()` yourself. An example is shown below:
```
reloadServer = reload(server, app, 1000);
watch.watchTree(__dirname + "/public", function (f, curr, prev) {
console.log("Trying to reload...");
reloadServer.reload();
});
```

@@ -205,2 +217,1 @@ API

Copyright 2013, JP Richardson <jprichardson@gmail.com>

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc