Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Last active August 29, 2015 14:19
Show Gist options
  • Save 3rd-Eden/2375c9987221bca89097 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/2375c9987221bca89097 to your computer and use it in GitHub Desktop.
lfg.js
'use strict';
var fs = require('fs')
, path = require('path')
, Primus = require('primus')
, EventEmitter = require('events').EventEmitter
, Socket = Primus.createSocket({ transformer: 'engine.io' });
var server = require('http').createServer(function (req, res) {
res.setHeader('Content-Type', 'text/html');
if ('/' === req.url) {
return require('fs').createReadStream(path.join(__dirname, 'index.html')).pipe(res);
}
res.setHeader('Content-Type', 'text/javascript');
require('fs').createReadStream(path.join(__dirname, 'primus.js')).pipe(res);
}).listen(8080);
//
// We can attach to server, but EventEmitter works fine because our local server
// doesn't need any real-time magic.
//
var primus = new Primus(new EventEmitter(), {
transformer: 'engine.io'
});
//
// Save the compiled server as primus.js
//
primus.save(path.join(__dirname ,'primus.js'));
{
"name": "gist",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"engine.io": "1.5.1",
"engine.io-client": "1.5.1",
"pem": "1.7.2",
"primus": "3.0.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment