Skip to content

Commit 44b3c9f

Browse files
authored
Merge pull request #25 from rogelio-o/develop
Develop
2 parents 042ce3c + 828808f commit 44b3c9f

9 files changed

Lines changed: 19 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { AWSHandler } from "lambda-framework-aws";
6262
const app: IApp = new App();
6363
...
6464
const handler: AWSHandler = new AWSHandler(app);
65-
export.handler = handler.handle;
65+
export const handle = handler.handle.bind(handler);
6666
```
6767

6868
### Event handling

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"devDependencies": {
3030
"@types/chai": "^4.0.4",
3131
"@types/mocha": "^2.2.43",
32-
"@types/node": "^8.0.28",
3332
"@types/sinon": "^2.3.7",
3433
"chai": "^4.1.2",
3534
"coveralls": "^3.0.0",
@@ -43,6 +42,7 @@
4342
"typescript": "^2.5.2"
4443
},
4544
"dependencies": {
45+
"@types/node": "^8.0.28",
4646
"accepts": "^1.3.4",
4747
"bytes": "^3.0.0",
4848
"content-type": "^1.0.4",

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export { default as configuration } from "./lib/configuration/configuration";
1010
export { default as IApp } from "./lib/types/IApp";
1111
export { default as INext } from "./lib/types/INext";
1212
export { default as IRouter } from "./lib/types/IRouter";
13+
export { default as Router } from "./lib/Router";
1314

1415
export { default as IEventHandler } from "./lib/types/event/IEventHandler";
1516
export { default as IEventLayer } from "./lib/types/event/IEventLayer";

src/lib/App.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ export default class App implements IApp {
118118
console.error(err instanceof HttpError ? err.cause.message : err.message);
119119
} else {
120120
if (req instanceof EventRequest) {
121-
console.log("No handlers for " + JSON.parse(req.event));
121+
if (!req.processed) {
122+
console.log("No handlers for " + JSON.stringify(req.event.original));
123+
}
122124
} else if (req instanceof HttpRequest) {
123125
console.log("No handlers for " + req.method + " " + req.path);
124126
} else {

src/lib/event/EventRequest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import IRawEvent from "./../types/IRawEvent";
88
export default class EventRequest implements IEventRequest {
99

1010
public next: INext;
11+
public processed: boolean;
1112

1213
private _event: IRawEvent;
1314
private _context: { [name: string]: any };
1415

1516
constructor(event: IRawEvent) {
17+
this.processed = false;
1618
this._event = event;
1719
this._context = {};
1820
}

src/lib/event/EventRouterExecutor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default class EventRouterExecutor implements IEventRouterExecutor {
5454
// We process only error handlers if there is an error
5555
this.next(error);
5656
} else {
57+
this._req.processed = true;
5758
layer.handle(this._req, this.next.bind(this), error);
5859
}
5960
} else if (this._subrouterIndex < this._router.subrouters.length) {

src/lib/http/bodyParsers/UrlEncodedParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class UrlEncodedParser implements IBodyParser {
8181
const queryParser: (body: string, parameterLimit: number, arrayLimit: number) => {[name: string]: string|string[]} = extended
8282
? extendedParser
8383
: simpleParser;
84-
const parser: (body: string) => {[name: string]: string|string[]} = abstractParser(options, queryParser);
84+
const parser: (body: string) => {[name: string]: string|string[]} = abstractParser(opts, queryParser);
8585

8686
return parserHelper(
8787
(initialBody: string, req: IHttpRequest): void => {

src/lib/http/bodyParsers/parserHelper.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import IHttpRequest from "./../../types/http/IHttpRequest";
44
import IHttpResponse from "./../../types/http/IHttpResponse";
55
import INext from "./../../types/INext";
66

7+
const canBeParsed = (body: string | { [name: string]: any }) => {
8+
return body && typeof body === "string";
9+
};
10+
711
/**
812
* Abtraction of the parser conditions and fallback mechanism.
913
*
@@ -16,15 +20,16 @@ const parserHelper = (func: (body: string, req: IHttpRequest) => void, allowCont
1620
return (req: IHttpRequest, res: IHttpResponse, next: INext) => {
1721
let error;
1822

19-
if (req.body && !req.context._previouslyBodyParsed) {
23+
if (canBeParsed(req.body) && !req.context._previouslyBodyParsed) {
24+
const initialBody = req.body;
2025
if (!allowContentTypes || req.is(allowContentTypes)) {
2126
const contentType = req.header("content-type");
2227
try {
2328
func(req.body as string, req);
2429

2530
req.context._previouslyBodyParsed = true;
2631
} catch (e) {
27-
console.log("400 " + req.method + " " + req.path + ": Body can not be parsed: " + req.body, e);
32+
console.log("400 " + req.method + " " + req.path + ": Body can not be parsed: " + JSON.stringify(initialBody), e);
2833
if (e instanceof HttpError) {
2934
error = e;
3035
} else if (contentType) {

src/lib/types/event/IEventRequest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export default interface IEventRequest {
1111

1212
next: INext;
1313

14+
processed: boolean;
15+
1416
/**
1517
* Context to save thins and use it
1618
* in other handlers.

0 commit comments

Comments
 (0)