Created
November 2, 2013 18:09
-
-
Save edinella/7281746 to your computer and use it in GitHub Desktop.
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
// implementation | |
var Beat = require('beat'); | |
module.exports = function(alias) { | |
var app = new Beat(alias); | |
var BeatObject = function BeatObject(callback) { | |
for(var key in BeatObject) | |
if(BeatObject.hasOwnProperty(key)) { | |
var keyParts = key.match(/^(.+)Factory$/); | |
if(keyParts === null) | |
app.value(key, BeatObject[key]); | |
else | |
app.factory(keyParts[1], BeatObject[key]); | |
} | |
return app.run(callback); | |
}; | |
return BeatObject; | |
}; | |
// usage | |
var BeatObject = require('beatObject'); | |
var beatApp = BeatObject(); | |
beatApp.port = process.env.npm_package_config_app_port || process.env.PORT; | |
beatApp.express = require('express'); | |
beatApp.appFactory = ['express', function(e){ | |
return e(); | |
}]; | |
beatApp.oneFactory = function(two){ | |
return 1; | |
}; | |
beatApp.twoFactory = function(/* port */ p){ | |
console.log(this); | |
return 2; | |
}; | |
beatApp(function(app, port, one){ | |
app.get('/hello.txt', function(req, res){ | |
res.send('Hello World'); | |
}); | |
app.listen(port); | |
console.log('Express ouvindo na porta '+port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment