diff --git a/README.md b/README.md index 508e1a1..3981c20 100644 --- a/README.md +++ b/README.md @@ -107,10 +107,10 @@ app.use(function staticsPlaceholder(req, res, next) { ``` #### server -Type: `String` +Type: `String|Object` Default: null -This option allows you to specify a path to a Node.js module that exports a "connect-like" object. Such object should have the following two functions: +This option allows you to specify a "connect-like" object. This can optionally be a path to a Node.js module that exports a such an object. Such object should have the following two functions: 1. `use(route, fn)` (https://github.com/senchalabs/connect/blob/master/lib/proto.js#L62) 2. `listen()` (https://github.com/senchalabs/connect/blob/master/lib/proto.js#L227) diff --git a/lib/util.js b/lib/util.js index 05e4144..b36195f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -89,17 +89,22 @@ exports.runServer = function runServer(grunt, options) { var server; if (options.server) { - try { - server = require(path.resolve(options.server)); - if (typeof server.listen !== 'function') { - grunt.fatal('Server should provide a function called "listen" that acts as http.Server.listen'); + if (typeof options.server === 'string') { + try { + server = require(path.resolve(options.server)); + } catch (e) { + var errorMessage = options.showStack ? '\n' + e.stack : e; + grunt.fatal('Server ["' + options.server + '"] - ' + errorMessage); } - if (typeof server.use !== 'function') { - grunt.fatal('Server should provide a function called "use" that acts as connect.use'); - } - } catch (e) { - var errorMessage = options.showStack ? '\n' + e.stack : e; - grunt.fatal('Server ["' + options.server + '"] - ' + errorMessage); + } else { + server = options.server; + } + + if (typeof server.listen !== 'function') { + grunt.fatal('Server should provide a function called "listen" that acts as http.Server.listen'); + } + if (typeof server.use !== 'function') { + grunt.fatal('Server should provide a function called "use" that acts as connect.use'); } } else { server = connect();