mixu/gluejs — pull request #29 by JibSales (2013-12-30 17:48:50+00:00)
Title: Express Middleware Support

My initial thought after finishing up is that this functionality belongs in a plugin/component and not core because it consumes the API rather than adds to it. However, the marketeer in me also knows that `gluejs` won't survive the unsteady waters of node module development unless the n00bs can plug-n-play. With that said, this feature is pretty straight forward and a good ground floor to begin supporting `express` out of the box.

I originally had a **highly** opinionated set of defaults that I eventually neglected for simplicity in setup. The interface I propose here only requires one parameter and all other options are left as opt-in – define them if you need them, ignore them and they'll be set to `glue`'s defaults. This gets you up on your feet quick.

I see the middleware being used two ways. First is using the typical `app.use()` middleware approach seen below:
```
var express = require('express');
var glue = require('gluejs').middleware;

var app = express();

app.use('/js/app.js', glue({
include: './public/js'
}));
```
Another way of saying the same thing:
```
app.use(app.router);
app.get('/js/app.js', glue({
include: './public/js'
}));
```
While the two interfaces are semantically the same, they introduce an interesting opportunity to push this middleware a step further. We could allow the user to pass an array of static route/options mappings like so:
```
app.use(glue([
{ path: '/js/foo.js', include: './public/js/foo', options: { /* Other Options */ },
{ path: '/js/bar.js', include: './public/js/bar', options: { /* Other Options */ }
]));
```
The major benefit of the above is giving the user the ability to define each endpoint in an out-of-file configuration that can be loaded when needed:
```
app.use(glue(require('./config.json'));
```
Alternatively, then they could use the following interface to define endpoints one-at-a-time:
```
app.get('/js/foo.js', glue({ include: './public/js/foo', options: { /* Other Options */ } });
app.get('/js/bar.js', glue({ include: './public/js/bar', options: { /* Other Options */ } });
```
Let me know what you think of both the PR and the above proposed next steps. If this seems like the direction you want to take, I will submit another PR reflecting those changes.