Skip to content
This repository has been archived by the owner on Jan 2, 2020. It is now read-only.

Commit

Permalink
initial repo creation
Browse files Browse the repository at this point in the history
  • Loading branch information
intabulas committed Mar 1, 2012
0 parents commit 24f4024
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
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 added README.md
Empty file.
19 changes: 19 additions & 0 deletions lib/index.js
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;
});
23 changes: 23 additions & 0 deletions lib/plugins/version_parser.js
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;
7 changes: 7 additions & 0 deletions package.json
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"
}

0 comments on commit 24f4024

Please sign in to comment.