et
Version:
effortlessness, et al.
72 lines (64 loc) • 1.75 kB
JavaScript
// Generated by CoffeeScript 1.4.0
var Et, Restify;
Restify = require('restify');
Et = (function() {
function Et() {
this.logger = require('./logger');
this.session = require('./session');
this.model = require('./model');
this.auth = require('./auth');
this["static"] = require('./static');
this.route = require('./route');
}
Et.prototype.al = function(opts) {
var et, gotApp;
if (opts == null) {
opts = {};
}
console.log('init et.al()');
this.resource = opts.resource;
et = this;
gotApp = opts.app !== void 0;
opts.name || (opts.name = process.env.APP_NAME || 'untitled');
opts.version || (opts.version = process.env.APP_VERSION || '0.0.0');
opts.port || (opts.port = process.env.APP_PORT || 3000);
if (!gotApp) {
opts.app = Restify.createServer({
name: opts.name,
version: opts.version
});
}
opts.app.use(this.logger.config(this, opts));
this.first = function(req, res, next) {
req.et = et;
return next();
};
opts.app.use(this.first);
this.last = function(req, res, next) {
console.warn('UNHANDLED request ', req.path);
return next();
};
if (opts.before instanceof Function) {
opts.before(opts.app);
}
this.session.config(this, opts);
this.model.config(this, opts);
this.auth.config(this, opts);
if (opts.use instanceof Function) {
opts.use(opts.app);
}
this["static"].config(this, opts);
this.route.config(this, opts);
et.log.debug({
opts: opts
});
if (gotApp) {
return this.last;
} else {
opts.app.listen(opts.port);
}
return opts.app;
};
return Et;
})();
module.exports = new Et();