krakenjs/express-enrouten — pull request #47 by sixlettervariables (2014-08-17 22:07:20+00:00)
Title: Directory mode: process files with index.js before all others

This PR changes the default behavior of express-enrouten to process files in directory mode alphabetically (explicitly) and to process `index.js` before all other files. This allows *slightly* more predictable route handling as structures get more complex. With this change, routes which *must* go earlier can be put into `index.js` for the given level.

Old behavior:

```
[development] Listening on http://localhost:8000
[router] GET /about/ (./controllers/about.js)
[router] POST /amz-ses/ (./controllers/amz-ses.js)
[router] GET /ecgs/:ecg (./controllers/ecgs/index.js)
[router] POST /ecgs/:ecg (./controllers/ecgs/index.js)
[router] POST /ecgs/:ecg/tags (./controllers/ecgs/index.js)
[router] POST /ecgs/:ecg/signature (./controllers/ecgs/index.js)
[router] POST /ecgs/:ecg/uploaded (./controllers/ecgs/index.js)
[router] GET / (./controllers/index.js)
[router] GET /success (./controllers/index.js)
[router] GET /login/ (./controllers/login/index.js)
[router] POST /login/ (./controllers/login/index.js)
[router] GET /login/reset/ (./controllers/login/reset.js)
[router] POST /login/reset/ (./controllers/login/reset.js)
[router] GET /login/reset/sent (./controllers/login/reset.js)
...
```
New behavior:

```
[development] Listening on http://localhost:8000
[router] GET / (./controllers/index.js)
[router] GET /success (./controllers/index.js)
[router] GET /about/ (./controllers/about.js)
[router] POST /amz-ses/ (./controllers/amz-ses.js)
[router] GET /ecgs/:ecg (./controllers/ecgs/index.js)
[router] POST /ecgs/:ecg (./controllers/ecgs/index.js)
[router] POST /ecgs/:ecg/tags (./controllers/ecgs/index.js)
[router] POST /ecgs/:ecg/signature (./controllers/ecgs/index.js)
[router] POST /ecgs/:ecg/uploaded (./controllers/ecgs/index.js)
[router] GET /login/ (./controllers/login/index.js)
[router] POST /login/ (./controllers/login/index.js)
[router] GET /login/reset/ (./controllers/login/reset.js)
[router] POST /login/reset/ (./controllers/login/reset.js)
[router] GET /login/reset/sent (./controllers/login/reset.js)
...
```

This may be a breaking change for some consumers if they rely on the current behavior for proper route selection (perhaps on case-insensitive file systems).