Skip to content

Instantly share code, notes, and snippets.

@lpinca
Created July 24, 2014 16:52
Show Gist options
  • Save lpinca/2ad7f3920edfac342c3a to your computer and use it in GitHub Desktop.
Save lpinca/2ad7f3920edfac342c3a to your computer and use it in GitHub Desktop.
GH-268
var primus = new Primus({ strategy: false });
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script src="/primus/primus.js"></script>
<script src="/client.js"></script>
</body>
</html>
{
"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"
}
var httpProxy = require('http-proxy');
var proxy = new httpProxy.createProxyServer({
target: {
host: 'localhost',
port: 3000
},
ws: true
});
proxy.listen(8080);
'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