Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -26,6 +26,9 @@
"serverless"
],
"author": "Krishna Kant Sharma <kks@krishnakantsharma.com>",
"contributors": [
"Ifiok Idiang <ifiok@ifiok.com>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/kksharma1618/lambda-restify/issues"
Expand All @@ -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": {
Expand Down
10 changes: 8 additions & 2 deletions src/lib/body_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,4 +29,4 @@ export default function(req, res, next) {
break
}
next()
}
}
18 changes: 9 additions & 9 deletions src/lib/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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
}
Expand Down