-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
executable file
·38 lines (31 loc) · 1009 Bytes
/
server.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
var express = require("express");
var tinylr = require("tiny-lr");
var broccoli = require("broccoli");
var brocware = require("broccoli/lib/middleware");
var Watcher = require("broccoli/lib/watcher");
var server = express();
var lrServer = new tinylr.Server();
var tree = broccoli.loadBrocfile();
var watcher = new Watcher(new broccoli.Builder(tree));
var HOST = "0.0.0.0";
var PORT = 9000;
var LR_PORT = 35729;
var proxy = function(req, res, next) {
if (req.url !== "/") {
// Redirect everything that does not contain a dot to /index.html
// (assuming that everything else is a file, like favicon.ico)
if (!req.url.match(/\./)) {
req.url = "/index.html";
}
}
next();
};
watcher.on("change", function() {
lrServer.changed({ body: { files: ["LiveReload files"] }});
}).on("error", function(error){
console.log(error.message, error.stack);
});
server.use(proxy);
server.use(brocware(watcher));
lrServer.listen(LR_PORT);
server.listen(PORT, HOST);