-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreload.js
42 lines (33 loc) · 967 Bytes
/
reload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(function () {
'use strict';
var fs = require('fs'),
http = require('http'),
express = require('express'),
app = express(),
server = http.createServer(app),
io = require('socket.io')(server),
filename = __dirname + '/static/VandA.otf',
prevChange = -Infinity;
function now () {
return process.hrtime()[0];
}
fs.watchFile(filename, function (event, filename) {
var currChange = now();
/**
* ensure 3 seconds between each change
*/
if (currChange - prevChange > 3) {
io.emit('file::change', currChange);
prevChange = currChange;
console.log('file changed');
}
});
app.use(express.static(__dirname + '/static'));
app.get('/', function (req, res) {
res.sendfile(__dirname + '/static/index.html');
});
server.listen(8080, function () {
var address = server.address();
console.log('running on http://127.0.0.1:%j', address.port);
});
})();