Permalink
Browse files

remove lib/index.js

Needless level of indirection which blocks actually reading the
important parts of the code.
  • Loading branch information...
1 parent d3ed841 commit cb2b80afd9f8cdaf82ef0605edf93cf6df30f947 @defunctzombie defunctzombie committed Jan 20, 2014
Showing with 28 additions and 4 deletions.
  1. +2 −2 index.js
  2. +19 −2 lib/engine.io.js
  3. +7 −0 test/engine.io.js
View
4 index.js
@@ -1,4 +1,4 @@
module.exports = process.env.EIO_COV
- ? require('./lib-cov')
- : require('./lib');
+ ? require('./lib-cov/engine.io')
+ : require('./lib/engine.io');
View
21 lib/engine.io.js
@@ -5,6 +5,19 @@
var http = require('http');
/**
+ * Invoking the library as a function delegates to attach
+ *
+ * @param {http.Server} server
+ * @param {Object} options
+ * @return {Server} engine server
+ * @api public
+ */
+
+exports = module.exports = function() {
+ return attach.apply(this, arguments);
+};
+
+/**
* Protocol revision number.
*
* @api public
@@ -62,7 +75,9 @@ exports.parser = require('engine.io-parser');
* @api public
*/
-exports.listen = function (port, options, fn) {
+exports.listen = listen;
+
+function listen(port, options, fn) {
if ('function' == typeof options) {
fn = options;
options = {};
@@ -91,7 +106,9 @@ exports.listen = function (port, options, fn) {
* @api public
*/
-exports.attach = function (server, options) {
+exports.attach = attach;
+
+function attach(server, options) {
var engine = new exports.Server(options);
engine.attach(server, options);
return engine;
View
7 test/engine.io.js
@@ -38,6 +38,13 @@ describe('engine', function () {
});
describe('attach()', function () {
+ it('should work from require()', function () {
+ var server = http.createServer();
+ var engine = eio(server);
+
+ expect(engine).to.be.an(eio.Server);
+ });
+
it('should return an engine.Server', function () {
var server = http.createServer()
, engine = eio.attach(server);

0 comments on commit cb2b80a

Please sign in to comment.