Last active
December 11, 2015 08:48
-
-
Save xjamundx/4575166 to your computer and use it in GitHub Desktop.
Versioned APIs with Express
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
| // define the versions | |
| var VERSIONS = {'Pre-Production': '/v0', 'Version 1': '/v1'}; | |
| // route to display versions | |
| app.get('/', function(req, res) { | |
| res.json(VERSIONS); | |
| }) | |
| // versioned routes go in the routes/ directory | |
| // import the routes | |
| for (var k in VERSIONS) { | |
| app.use(VERSIONS[k], require('./routes' + VERSIONS[k])); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment