express-enrouten
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -0,1 +1,9 @@ | ||
##### v0.2.1 - 20140210 | ||
**Bugs** | ||
- Fix order of scanning and router placement to ensure middleware comes before router. | ||
- Fix file scanning to support all registered/supported Node.js file extensions. | ||
**Features** | ||
- n/a | ||
##### v0.2.0 - 20140127 | ||
@@ -2,0 +10,0 @@ **Bugs** |
/*───────────────────────────────────────────────────────────────────────────*\ | ||
│ Copyright (C) 2013 eBay Software Foundation │ | ||
│ Copyright (C) 2014 eBay Software Foundation │ | ||
│ │ | ||
@@ -4,0 +4,0 @@ │hh ,'""`. │ |
27
index.js
/*───────────────────────────────────────────────────────────────────────────*\ | ||
│ Copyright (C) 2013 eBay Software Foundation │ | ||
│ Copyright (C) 2014 eBay Software Foundation │ | ||
│ │ | ||
@@ -30,3 +30,18 @@ │hh ,'""`. │ | ||
function tryResolve(file) { | ||
try { | ||
// remove the file extension | ||
var ext = path.extname(file); | ||
if (ext) { | ||
file = file.replace(new RegExp('\\' + ext + '$'), ''); | ||
} | ||
// and use require.extensions to resolve known file types eg. CoffeeScript | ||
require.resolve(file); | ||
return true; | ||
} catch (err) { | ||
return false; | ||
} | ||
} | ||
function scan(file, controllers) { | ||
@@ -47,3 +62,3 @@ var stats; | ||
}); | ||
} else if (stats.isFile() && file.match(/\.js$/i)) { | ||
} else if (stats.isFile() && tryResolve(file)) { | ||
controllers.push(file); | ||
@@ -108,5 +123,9 @@ } | ||
scan(app, settings); | ||
// Reorganize stack to place router in correct place | ||
// This could get out of whack if someone registers | ||
// directly against express prior to calling enrouten | ||
// directly against express prior to calling enrouten. | ||
// This is done *after* scanning so any middleware registered | ||
// during scanning is correctly put before the router. | ||
app.stack.some(function (middleware, idx, stack) { | ||
@@ -120,4 +139,2 @@ if (middleware.handle.name === 'router') { | ||
}); | ||
scan(app, settings); | ||
}; | ||
@@ -124,0 +141,0 @@ } |
/***@@@ BEGIN LICENSE @@@***/ | ||
/*───────────────────────────────────────────────────────────────────────────*\ | ||
│ Copyright (C) 2013 eBay Software Foundation │ | ||
│ Copyright (C) 2014 eBay Software Foundation │ | ||
│ │ | ||
@@ -5,0 +5,0 @@ │hh ,'""`. │ |
{ | ||
"name": "express-enrouten", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "An express route initialization and configuration module.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,4 +8,4 @@ express-enrouten | ||
[![Build Status](https://travis-ci.org/paypal/express-enrouten.png)](https://travis-ci.org/paypal/express-enrouten) | ||
[![NPM version](https://badge.fury.io/js/express-enrouten.png)](http://badge.fury.io/js/express-enrouten) | ||
### API | ||
@@ -22,3 +22,3 @@ #### `app.use(enrouten(options))` | ||
~~#### `enrouten(app).withRoutes(options)`~~ | ||
#### **Deprecated:** ~~`enrouten(app).withRoutes(options)`~~ | ||
```javascript | ||
@@ -83,4 +83,4 @@ var express = require('express'), | ||
### Controller Files | ||
A 'controller' is defined as any javascript file (extension of `.js`) which exports a function that accepts a single argument. | ||
**NOTE: Any file in the directory tree that matches the API will be invoked/initialized with the express application object.** | ||
A 'controller' is defined as any `require`-able file which exports a function that accepts a single argument. Any files with an extension of `.js` (or `.coffee` if CoffeeScript is registered) will be loaded and if it exports a function that accepts a single argument then this function will be called. **NOTE: Any file in the directory tree that matches the API will be invoked/initialized with the express application object.** | ||
```javascript | ||
@@ -87,0 +87,0 @@ // Good :) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19778
162
5