Created
July 24, 2014 16:52
-
-
Save lpinca/2ad7f3920edfac342c3a to your computer and use it in GitHub Desktop.
GH-268
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var primus = new Primus({ strategy: false }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<script src="/primus/primus.js"></script> | |
<script src="/client.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "gh-268", | |
"version": "0.0.0", | |
"description": "", | |
"main": "server.js", | |
"dependencies": { | |
"engine.io": "^1.3.1", | |
"http-proxy": "^1.1.6", | |
"primus": "^2.3.0" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "node server.js" | |
}, | |
"author": "", | |
"license": "MIT" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var httpProxy = require('http-proxy'); | |
var proxy = new httpProxy.createProxyServer({ | |
target: { | |
host: 'localhost', | |
port: 3000 | |
}, | |
ws: true | |
}); | |
proxy.listen(8080); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var fs = require('fs') | |
, Primus = require('primus'); | |
var server = require('http').createServer(function (req, res) { | |
if (req.url === '/client.js') { | |
res.setHeader('Content-Type', 'application/javascript'); | |
fs.createReadStream(__dirname + '/client.js').pipe(res); | |
return; | |
} | |
res.setHeader('Content-Type', 'text/html'); | |
fs.createReadStream(__dirname + '/index.html').pipe(res); | |
}); | |
var primus = new Primus(server, { transformer: 'engine.io' }); | |
primus.on('connection', function(spark) { | |
console.log(spark.id + ' connected'); | |
}).on('disconnection', function(spark) { | |
console.log(spark.id + ' disconnected'); | |
}); | |
server.listen(3000, function () { | |
console.log('listening on port 3000'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment