This repository has been archived by the owner on Jan 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 24f4024
Showing
5 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
node_modules | ||
npm-debug.log | ||
*.chproj | ||
.settings.xml | ||
API.json | ||
API.html |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2012 Mark Lussier All rights reserved. | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
// Exports | ||
|
||
module.exports = {}; | ||
|
||
// Just load up all the JS in this directory and export it. | ||
fs.readdirSync(__dirname + "/plugins").forEach(function (file) { | ||
if (!/.+\.js$/.test(file)) | ||
return; | ||
|
||
var plugin = require('./' + path.basename(file, '.js')); | ||
|
||
if (plugin && plugin.name) | ||
module.exports[plugin.name] = plugin; | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2012 Mark Lussier, All rights reserved. | ||
|
||
/** | ||
* Returns a plugin that will extract the api version from the Accept header in an very | ||
* opinionated form. ie: Accept: application/vnd.intabulas+json; version >= 1.0 | ||
* | ||
* @param {String} optional regular expression to override the default | ||
* @return {Function} restify handler. | ||
*/ | ||
function versionParser(expression) { | ||
if (!expression) | ||
expression = /;[ ]*version[ :=]+([^$;]+)/i | ||
|
||
return function parseAcceptVersion(req, res, next) { | ||
|
||
api_version = req.headers['accept'].match(expression); | ||
if ( api_version) | ||
req.headers['X-Api-Version'] = api_version[1]; | ||
return next(); | ||
}; | ||
} | ||
|
||
module.exports = versionParser; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ "name" : "restify-moreversion" | ||
, "version" : "0.0.1" | ||
, "description" : "Restify middleware that will extract the API version from the Accept header" | ||
"main": "lib/index.js", | ||
"directories": { "lib": "./lib"} | ||
, "repository" : "git://github.com/intabulas/restify-plugins.git" | ||
} |