diff options
Diffstat (limited to 'app/node_modules/okserver/index.js')
| -rw-r--r-- | app/node_modules/okserver/index.js | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/app/node_modules/okserver/index.js b/app/node_modules/okserver/index.js index 1645eaa..a89676f 100644 --- a/app/node_modules/okserver/index.js +++ b/app/node_modules/okserver/index.js @@ -16,6 +16,8 @@ function OKServer(options) { throw new Error('No admin root directory provided to OKServer'); if (!options.adminPath) throw new Error('No admin path provided to OKServer'); + if (!options.errorHandler) + throw new Error('No error handler provided to OKServer'); var root = options.root; var adminRoot = options.adminRoot; var adminPath = options.adminPath; @@ -25,6 +27,7 @@ function OKServer(options) { var router = express.Router({ strict: app.get('strict routing') }); + var error = options.errorHandler; var services = options.services || {}; Object.keys(views) // Sort such that more general routes are matched last @@ -49,11 +52,8 @@ function OKServer(options) { * other middleware. */ - // Intercept favicon requests and 404 for now - app.use('/favicon.ico', function(req, res) { - res.status(404) - return res.send(''); - }); + // Disable x-powered-by express header + app.disable('x-powered-by') // Serve user static files app.use(express.static(root)); // Serve admin interface static files @@ -61,22 +61,16 @@ function OKServer(options) { // Application router app.use(router); // Add services - if (services.image) { - app.use('/_services/image', services.image.middleware()); - } + Object.keys(services).forEach(function(key){ + app.use('/_services/' + key, services[key].middleware()); + }) // Make sure this lady is last. Checks whether the desired // route has a trailing-slash counterpart and redirects there app.use(slash()); - - /** - * Create a handler which redirect all requests to - * the same route with a trailing slash appended - */ - function redirect(routeNoSlash) { - return function(req, res) { - res.redirect(301, routeNoSlash + '/'); - } - } + // Otherwise it's a 404 + app.use(function(req, res) { + error(req, res, 404)(new Error('No matching route')); + }); } OKServer.prototype.listen = function listen(port) { |
