Comparing version 0.1.3 to 0.1.4
16
index.js
@@ -1,2 +0,2 @@ | ||
module.exports = function(app, dir) { | ||
var expo = module.exports = function(app, dir) { | ||
require('./lib/app')(app); | ||
@@ -6,1 +6,15 @@ app.root = dir; | ||
}; | ||
/** | ||
* Middleware proxy to express.errorHandler, but let 404 errors through. | ||
* | ||
* app.use(app.errorHandler(express.errorHandler)); | ||
*/ | ||
expo.errorHandler = function(handler) { | ||
return function(err, req, res, next) { | ||
if (err === 404) return next(404); | ||
handler(err, req, res, next); | ||
}; | ||
}; | ||
@@ -67,4 +67,4 @@ var path = require('path'); | ||
// Hooks: do pre-load hooks that extensions may listen for. | ||
events.emit('load:before', app); | ||
if (env === 'test') events.emit('load:test:before', app); | ||
app.emit('load:before'); | ||
if (env === 'test') app.emit('load:test:before'); | ||
@@ -86,7 +86,5 @@ // Load initializers of the application. | ||
// After hooks | ||
if (env === 'test') events.emit('load:test:after', app); | ||
events.emit('load:after', app); | ||
if (env === 'test') app.emit('load:test:after'); | ||
app.emit('load:after'); | ||
if (env === 'test') app.log.debug('App loaded for test environment'); | ||
loaded = true; | ||
@@ -98,2 +96,12 @@ } | ||
/** | ||
* Loads the app in a console-friendly way. Environment optional. | ||
*/ | ||
app.loadConsole = function(env) { | ||
app.load(env); | ||
app.emit('console'); | ||
global.app = app; | ||
}; | ||
var command; | ||
@@ -114,3 +122,3 @@ | ||
require('./cli')(app, command); | ||
events.emit('cli', app, command); | ||
app.emit('cli', command); | ||
loadModules(app.path('app/tasks'), 'function', function(mixin) { mixin(app, command); }); | ||
@@ -162,2 +170,14 @@ } | ||
/** | ||
* Emits an event. | ||
* | ||
* app.emit('load:before'); | ||
* app.emit('cli', app.cli); | ||
*/ | ||
app.emit = function(eventName, arg) { | ||
events.emit(eventName, app, arg); | ||
return this; | ||
}; | ||
// Config | ||
@@ -201,3 +221,2 @@ // ------ | ||
// Private helpers | ||
@@ -204,0 +223,0 @@ // --------------- |
@@ -42,3 +42,3 @@ /** | ||
.action(function() { | ||
global.app = app.load(); | ||
app.loadConsole(); | ||
require('repl').start({}); | ||
@@ -45,0 +45,0 @@ }); |
@@ -40,3 +40,3 @@ // Runner | ||
var supervisor = require('supervisor'); | ||
supervisor.run(['-n', 'exit', '-q', '-e', 'node|js|coffee', '--', process.argv[1], 'server', port, 'Q']); | ||
supervisor.run(['-q', '-e', 'node|js|coffee', '--', process.argv[1], 'server', port, 'Q']); | ||
} | ||
@@ -47,5 +47,18 @@ | ||
app.log.info('Ready [' + elapsed + 'ms]'); | ||
catchExceptions(); | ||
app.listen(port); | ||
} | ||
/** | ||
* Print unhandled exceptions and terminate | ||
*/ | ||
function catchExceptions() { | ||
if (app.get('env') === 'development') { | ||
process.on('exit', function() { | ||
app.log.debug('Restarting...'); | ||
}); | ||
} | ||
} | ||
function timestamp() { | ||
@@ -52,0 +65,0 @@ return (new Date()).toString().split(' ')[4]; |
@@ -6,3 +6,3 @@ { | ||
"author": "Rico Sta. Cruz", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"engines": { "node": ">=0.8.0" }, | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -0,1 +1,2 @@ | ||
var expo = require('expo'); | ||
var express = require('express'); | ||
@@ -18,4 +19,4 @@ | ||
app.configure('development', function() { | ||
app.use(express.errorHandler()); | ||
app.use(expo.errorHandler(express.errorHandler())); | ||
}); | ||
}; |
@@ -12,3 +12,4 @@ { | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha -R spec --compilers coffee:coffee-script" | ||
"test": "./node_modules/.bin/mocha -R spec --compilers coffee:coffee-script", | ||
"autotest": "./node_modules/.bin/mocha -R min --compilers coffee:coffee-script --watch -b" | ||
}, | ||
@@ -15,0 +16,0 @@ "dependencies": { |
28806
745