forked from chemzqm/liveload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (36 loc) · 1.03 KB
/
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
39
40
41
42
var connect = require('connect')
, http = require('http')
, path = require('path')
, io = require('socket.io')
, httpProxy = require('http-proxy')
, liveload = require('./lib/liveload')
, fs = require('fs');
var proxy = new httpProxy.RoutingProxy();
var root = __dirname;
var app = connect()
var server = http.createServer(app);
io = io.listen(server);
app.use(connect.cookieParser())
.use(connect.session({secret:"SSSeee!"}))
.use(liveload({io:io, root:root,socket:true}))
//serve static files
.use(connect['static'](root))
.use(function(req, res, next){
//revert proxy
if(/\/schneider\//.test(req.url)){
proxy.proxyRequest(req, res, {
host:'ec2-54-241-119-97.us-west-1.compute.amazonaws.com',
port:80
});
}else{
next();
}
});
server.listen(3000);
io.sockets.on('connection', function (socket){
console.log('client connected');
socket.on('disconnect',function(){
console.log('client disconnected');
});
});
console.log('server listening at 3000');