blai/grunt-express — pull request #67 by benhutchins (2014-07-31 17:43:52+00:00)
Title: Allow "connect-like" object to be passed to grunt-express as the "server"

Allow "connect-like" object to be passed to grunt-express as the "server" rather than just a string.

This allows for grunt to pass configuration to the server, such as things from grunt.option or whatever it desires, and then build out the server and pass back the ready-object.

My use case for this is that I am building a grunt plugin which performs client-side unit testing. This plugin consumes grunt-express to start a localhost web server which generates the HTML pages for the tests. I want to pass in the list of dependencies for each test file to the web server from Grunt, or at least the paths where the test files live which are configured in the user's Gruntfile.js - currently there is no way for me to pass data to the server.js from grunt-express.

An example of how to use this:

*Gruntfile.js*
```js
var path = require('path');

module.exports = function(grunt) {
grunt.initConfig({
testEnvironment: {
// define the root of your project files
root: path.join(__dirname, 'src'),
// define the pattern to identify your unit tests
pattern: '**/*.unittests.js',
// define your global dependencies, relative to your root project
deps: [
'3rdparty/jquery.js'
]
}
});
};
```

*testEnvironment.js - grunt task consuming grunt-express*
```js
var path = require('path');

module.exports = function (grunt) {

grunt.registerTask('testEnvironment', function () {
var options = this.options({
deps: []
});

var config = {
// find all the test files matching the options
tests: findTests(options),
deps: options.deps
};

grunt.config.set('express:testEnvironment', {
options: {
port: 3000,
server: require(path.join(__dirname, 'lib', 'server.js'))(config)
}
});

grunt.task.run('express:testEnvironment');
});
};
```
*server.js*
```js
var express = require('express')
var app = express();

module.exports = function (config) {
// do stuff now
return app;
};
```

Currently there would be no way to pass configuration to the server prior to it starting. This allows that to happen. There are existing hooks to pass in middleware from grunt, but no way to do more advanced configuration. This allows the system to be a lot more robust.