Created
August 24, 2012 17:22
-
-
Save secretfader/3453130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express'), | |
| api = express(); | |
| var validateVersion = function (matched, def, callback) { | |
| var header = null; | |
| if (typeof def === 'function') { | |
| callback = def; | |
| def = false; | |
| } | |
| return function (req, res, next) { | |
| if (req.header('X-Transistor-Version')) { | |
| header = req.header('X-Transistor-Version'); | |
| } | |
| if (header && matched === header) { | |
| return callback(req, res, next); | |
| } else if (!header && def === true) { | |
| return callback(req, res, next); | |
| } | |
| return next(); | |
| } | |
| } | |
| api.get('/podcasts', | |
| validateVersion('2', function(req, res) { | |
| res.send('Hello from Version 2'); | |
| }) | |
| ); | |
| api.get('/podcasts', | |
| validateVersion('1', true, function (req, res) { | |
| res.send('Hello from Version 1'); | |
| }) | |
| ); | |
| api.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment