Skip to content

Commit

Permalink
Fixed doc for already working route method & disabled disfunct param\…
Browse files Browse the repository at this point in the history
…use methods
  • Loading branch information
mallocator committed Sep 7, 2016
1 parent 688e43a commit d2019ad
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,26 @@ req.incomingVersion - The version that came in on the request
req.acceptedVersion - The version that the handler has been configured to accept


### Router.param
### Router.route
```
router.param(name, [version], callback)
router.route(path, [version])
```

Not yet implemented.
Works the same way as the original router method, only now has an optional version parameter that works the same way
as the version parameter on the individual methods.


### Router.use
### Router.param
```
router.use([path], [version], [function, ...] function)
router.param(name, [version], callback)
```

Not yet implemented.


### Router.route
### Router.use
```
router.route(path, [version])
router.use([path], [version], [function, ...] function)
```

Will probably not be implemented. Instead make use of individual functions for the different request methods.
Not yet implemented.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ function Router(configuration = {}) {
}));
}
}
let originalParam = router.param;
router.param = (name, version, cb) => {
throw new Error('Not yet implemented');
};
router.use = (path, version, ...handlers) => {
throw new Error('Not yet implemented');
};
return router;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-version-router",
"version": "0.5.1",
"version": "0.5.2",
"description": "A router for express that manages api versioning.",
"license": "Apache-2.0",
"author": "Ravi Gairola <mallox@pyxzl.net>",
Expand Down
48 changes: 44 additions & 4 deletions test/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,55 @@ describe('Router', () => {
request(app).get('/test?v=1').expect(200, 'success').end(done);
});

it('should still support standard routing for multiple path definitions', done => {
var router = Router();
router.get('/test', 1, (req, res, next) => next());
router.get('/test', 1, (req, res) => res.end('success'));

var app = express();
app.use(router);
request(app).get('/test?v=1').expect(200, 'success').end(done);
});

it('should be able to support other request methods on the same path', done => {
var router = Router();
router.get('/test', 1, (req, res, next) => next(), (req, res) => res.end('success get'));
router.post('/test', 1, (req, res, next) => next(), (req, res) => res.end('success post'));
router.get('/test', 1, (req, res) => res.end('success get'));
router.post('/test', 1, (req, res) => res.end('success post'));

var app = express();
app.use(router);
request(app).get('/test').expect(404).end(() => {
request(app).get('/test?v=1').expect(200, 'success get').end(() => {
request(app).post('/test?v=1').expect(200, 'success post').end(done);
});
});
});

it('should support the standard route method', done => {
var router = Router();
router.route('/test')
.get((req, res) => res.end('success get'))
.post((req, res) => res.end('success post'));

var app = express();
app.use(router);
request(app).get('/test?v=1').expect(200, 'success get').end(() => {
request(app).post('/test?v=1').expect(200, 'success post').end(done);
request(app).get('/test').expect(200, 'success get').end(() => {
request(app).post('/test').expect(200, 'success post').end(done);
});
});

it('should support the route method with version', done => {
var router = Router();
router.route('/test', 1)
.get((req, res) => res.end('success get'))
.post((req, res) => res.end('success post'));

var app = express();
app.use(router);
request(app).get('/test').expect(404).end(() => {
request(app).get('/test?v=1').expect(200, 'success get').end(() => {
request(app).post('/test?v=1').expect(200, 'success post').end(done);
});
});
});
});

0 comments on commit d2019ad

Please sign in to comment.