From 79161e623f85af8419a8847b2fd88f3a1b64414f Mon Sep 17 00:00:00 2001 From: Benjamin Hutchins Date: Thu, 31 Jul 2014 13:24:58 -0400 Subject: [PATCH 1/2] Allow "connect-like" object to be passed to grunt-express as the "server" rather than just a string. --- README.md | 4 ++-- lib/util.js | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) 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..c46af55 100644 --- a/lib/util.js +++ b/lib/util.js @@ -89,17 +89,20 @@ 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); + } + + 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(); From 630eb331e5fdaf9f5006505506a1fdb4adad745e Mon Sep 17 00:00:00 2001 From: Benjamin Hutchins Date: Thu, 31 Jul 2014 14:11:25 -0400 Subject: [PATCH 2/2] Have to set `server` to `options.server` at some point. --- lib/util.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/util.js b/lib/util.js index c46af55..b36195f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -96,6 +96,8 @@ exports.runServer = function runServer(grunt, options) { var errorMessage = options.showStack ? '\n' + e.stack : e; grunt.fatal('Server ["' + options.server + '"] - ' + errorMessage); } + } else { + server = options.server; } if (typeof server.listen !== 'function') {