diff --git a/package.json b/package.json index 0f856b5..d7b70cc 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ "scripts": { "prepublish": "npm run build", "build": "tsc", - "test": "mocha -r ts-node/register src/**/*.spec.ts", - "testwatch": "mocha -r ts-node/register -w --watch-extensions ts src/**/*.spec.ts", - "lint": "tslint src/**/*.ts" + "test": "./node_modules/mocha/bin/mocha -r ts-node/register src/**/*.spec.ts", + "testwatch": "./node_modules/mocha/bin/mocha -r ts-node/register -w --watch-extensions ts src/**/*.spec.ts", + "lint": "./node_modules/tslint/bin/tslint src/**/*.ts" }, "repository": { "type": "git", @@ -26,6 +26,9 @@ "serverless" ], "author": "Krishna Kant Sharma ", + "contributors": [ + "Ifiok Idiang " + ], "license": "MIT", "bugs": { "url": "https://github.com/kksharma1618/lambda-restify/issues" @@ -46,6 +49,7 @@ "nodemon": "^1.11.0", "npm-run-series": "^1.0.0", "ts-node": "^3.0.4", + "tslint": "^5.10.0", "typescript": "^2.3.2" }, "dependencies": { diff --git a/src/lib/body_parser.ts b/src/lib/body_parser.ts index 1045aee..33d922a 100644 --- a/src/lib/body_parser.ts +++ b/src/lib/body_parser.ts @@ -6,10 +6,16 @@ export default function(req, res, next) { if (!req.body) { return next() } - const contentType = req.header('content-type') + let contentType = req.header('content-type') if (!contentType) { return next() } + const jsonPatternMatcher = new RegExp('^application/[a-zA-Z.]+\\+json'); + // map any +json to application/json + if (jsonPatternMatcher.test(contentType)) { + contentType = 'application/json'; + } + switch (contentType) { case 'application/x-www-form-urlencoded': req.body = qs.parse(req.rawBody) @@ -23,4 +29,4 @@ export default function(req, res, next) { break } next() -} \ No newline at end of file +} diff --git a/src/lib/router.ts b/src/lib/router.ts index f58dc8a..c6bc346 100644 --- a/src/lib/router.ts +++ b/src/lib/router.ts @@ -156,9 +156,9 @@ export default class Router extends EventEmitter { return } - for (let i = 0; i < routes.length; i++) { + for (const route of routes) { try { - params = matchURL(routes[i].path, req.path()) + params = matchURL(route.path, req.path()) // console.log('p', params, req.path()) } catch (e) { this.log.trace({ err: e }, 'error parsing URL') @@ -170,12 +170,12 @@ export default class Router extends EventEmitter { continue } - reverse = this.reverse[routes[i].path.source] + reverse = this.reverse[route.path.source] - if (routes[i].types.length && req.isUpload()) { + if (route.types.length && req.isUpload()) { candidates.push({ p: params, - r: routes[i] + r: route }) typed = true continue @@ -185,15 +185,15 @@ export default class Router extends EventEmitter { // not the first one. However, if neither the client nor // server specified any version, we're done, because neither // cared - if (routes[i].versions.length === 0 && req.version() === '*') { - r = routes[i] + if (route.versions.length === 0 && req.version() === '*') { + r = route break } - if (routes[i].versions.length > 0) { + if (route.versions.length > 0) { candidates.push({ p: params, - r: routes[i] + r: route }) versioned = true }