dizlexik/express-reverse — pull request #3 by Cisneiros (2014-06-20 01:03:03+00:00)
Title: The returned URLs now consider the apps's mountpath, if there is one.

The current implementation of express-reverse does not consider the possibility of the app being mounted on top of another app.

For example: I have an express app for an admin interface. It is a completely separate app. On my main project, I include the admin app as follows:

``` javascript
// main app
app.use('/admin', adminApp);
```

``` javascript
// admin app
app.get('edit-user', '/user/:id', function() { '…' });
```

All the routes on the admin app don't know that they are prefixed with '/admin'. In the current implementation, if my admin app tries to use the helper or the middleware, the resulting URL won't consider this.

``` jade
a(href=url('edit-user', {id: user.id})) Edit this user
// yelds: /user/5
// should be: /admin/user/5
```

This pull request changes the helper function and the middleware to prepend the app's mountpath, if there is one. Note that the mountpath is unknown during app setup, so instead of changing the `reverse` function, I've changed the middleware and helper functions.

Two new tests have been included to verify that it works as expected. The current tests, of course, still pass.