api-routes
Advanced tools
Comparing version
@@ -9,3 +9,3 @@ // api.js | ||
function Api (base) { | ||
function Api (base, opts) { | ||
this._router = new express.Router(); | ||
@@ -17,2 +17,6 @@ this.router = this._router.middleware; | ||
this.endpoints = {}; | ||
opts = opts || {}; | ||
this._router = opts.caseSensative || false; | ||
this._router = opts.strict || false; | ||
} | ||
@@ -115,3 +119,5 @@ | ||
var reqAll = require('require-all'); | ||
var routes = reqAll(opts); | ||
var routes = reqAll(_.defaults(opts, { | ||
filter: '(.*)\.js' | ||
})); | ||
this.execRoutes(routes); | ||
@@ -118,0 +124,0 @@ } |
{ | ||
"name": "api-routes", | ||
"description": "A declarative system for creating express API routes.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": "Jon Eisen <jon.m.eisen@gmail.com>", | ||
"scripts": { | ||
"example": "node example/server.js" | ||
"example": "node example/server.js", | ||
"test": "nodeunit tests" | ||
}, | ||
@@ -9,0 +10,0 @@ "devDependencies": { |
@@ -10,4 +10,2 @@ node-api-routes | ||
In order to support those goals, routes are defined in as many files as desired, express helpers are fully available, and declaring methods for a CRUD endpoint implicitly creates an OPTIONS verb. | ||
## Install & Usage | ||
@@ -22,2 +20,3 @@ | ||
```javascript | ||
var Api = require('api-routes'); | ||
var api = new Api('/api' /* base route */); | ||
@@ -35,4 +34,8 @@ | ||
// Or use the more organized requireAll | ||
// See below for examples on how files should be organized. | ||
api.requireAll({ | ||
dirname: __dirname + '/routes' | ||
// Same options as require-all package | ||
dirname: __dirname + '/routes', | ||
filter : /(.*)\.js$/, // optional | ||
excludeDirs : /^\.(git|svn)$/ //optional | ||
}); | ||
@@ -100,5 +103,8 @@ | ||
} | ||
``` | ||
Other features include inheritance via adding sub-endpoints using a period in the name, such as 'test.abc' being a child of endpoint 'test'. There is an example to show how to use this. | ||
## License | ||
MIT License found in [LICENSE](https://github.com/yanatan16/node-api-routes/blob/master/LICENSE) file. |
@@ -55,2 +55,10 @@ var tests = module.exports = {}; | ||
tests.authPass = makeTest('get', '/authtest?auth=true', 'authenticated!'); | ||
tests.authFail = function (test) { | ||
request('http://localhost:8000/api/authtest2', function (err, res, body) { | ||
test.ifError(err); | ||
test.equal(403, res.statusCode); | ||
test.done(); | ||
}); | ||
}; | ||
tests.authPass = makeTest('get', '/authtest2?auth=true', 'authenticated!'); | ||
@@ -57,0 +65,0 @@ tests.final = function (test) { |
13416
5.17%321
4.22%106
6%