Skip to content

Commit

Permalink
Eliminate bad notAllowedMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-boyd committed Sep 30, 2019
1 parent 3d6b832 commit 7e476bd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
21 changes: 1 addition & 20 deletions lib/expressroutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var async = require('async'),
path = require('path'),
thing = require('core-util-is'),
utils = require('swaggerize-routes/lib/utils'),
utils = require('swaggerize-routes-safe/lib/utils'),
pathRegexp = require('path-to-regexp');


Expand Down Expand Up @@ -156,21 +156,6 @@ function makeExpressRoute(router, mountpath, route, securityDefinitions) {
router[route.method].apply(router, args);
}

/**
* Builds the middleware to manage not allowed calls that use wrong Method
* @param methods - list of avalaible method for this request
* @return {function}
*/
function buildNotAllowedMiddleware(methods) {
return function (req, res, next) {
if (methods.indexOf(req.method.toLowerCase()) === -1) {
res.set('Allow', methods.join(', ').toUpperCase());
res.sendStatus(405).end();
}
next();
};
}

/**
* Routes handlers to express router.
* @param router
Expand All @@ -194,10 +179,6 @@ function expressroutes(router, options) {
routesMethod[routePath] = routesMethod[routePath] || [];
routesMethod[routePath].push(route.method.toLowerCase());
});

Object.keys(routesMethod).forEach(function (routePath){
router.use(pathRegexp(routePath), buildNotAllowedMiddleware(routesMethod[routePath]));
});
}


Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var assert = require('assert'),
caller = require('caller'),
expressroutes = require('./expressroutes'),
url = require('url'),
routes = require('swaggerize-routes'),
routes = require('swaggerize-routes-safe'),
yaml = require('js-yaml'),
fs = require('fs');

Expand Down

0 comments on commit 7e476bd

Please sign in to comment.