Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalanamini committed Oct 21, 2018
1 parent 8587a83 commit 489236a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"dependencies": {
"@foxify/inject": "^1.0.0",
"@types/node": "^10.11.7",
"@types/node": "^10.12.0",
"@types/range-parser": "^1.2.2",
"accepts": "^1.3.5",
"async": "^2.6.1",
Expand Down Expand Up @@ -83,7 +83,7 @@
},
"devDependencies": {
"@types/accepts": "^1.3.5",
"@types/async": "^2.0.49",
"@types/async": "^2.0.50",
"@types/content-disposition": "^0.5.2",
"@types/content-type": "^1.1.2",
"@types/cookie": "^0.3.1",
Expand Down Expand Up @@ -114,7 +114,7 @@
"tslint": "^5.11.0",
"typedoc": "^0.13.0",
"typedoc-plugin-example-tag": "^1.0.2",
"typescript": "^3.1.2",
"typescript": "^3.1.3",
"uglify-es": "^3.3.9"
},
"jest": {
Expand Down
5 changes: 0 additions & 5 deletions src/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ class Request extends http.IncomingMessage {
*/
settings!: Request.Settings;

/**
* @hidden
*/
next!: () => void;

/**
* @hidden
*/
Expand Down
26 changes: 20 additions & 6 deletions src/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,27 @@ class Response extends http.ServerResponse {
/**
* @hidden
*/
req!: Request;
stringify!: { [statusCode: number]: any };

/**
* @hidden
*/
stringify!: { [statusCode: number]: any };
next!: () => void;

/**
* @hidden
*/
req: Request;

/**
*
* @param req request
*/
constructor(req: Request) {
super(req);

this.req = req;
}

/**
* Check if the request is fresh, aka
Expand Down Expand Up @@ -563,7 +578,7 @@ class Response extends http.ServerResponse {
*/
format(obj: object) {
const req = this.req;
const next = req.next;
const next = this.next;

const fn = (obj as { [key: string]: any }).default;

Expand Down Expand Up @@ -894,8 +909,7 @@ class Response extends http.ServerResponse {
sendFile(path: string, options?: object | ((...args: any[]) => void), callback?: (...args: any[]) => void) {
let done = callback;
const req = this.req;
const res = this;
const next = req.next;
const next = this.next;
let opts = options || {};

if (!path) throw new TypeError("path argument is required to res.sendFile");
Expand All @@ -914,7 +928,7 @@ class Response extends http.ServerResponse {
const file = send(req, pathname, opts);

// transfer
sendfile(res, file, opts, (err: any) => {
sendfile(this, file, opts, (err: any) => {
if (done) return done(err);
if (err && err.code === "EISDIR") return next();

Expand Down
4 changes: 1 addition & 3 deletions src/routing/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class Router {

const next = () => this._safeNext.run(req, res, handlers, index + 1);

req.next = next;
res.next = next;

handler.run(req, res, next);
}
Expand Down Expand Up @@ -584,8 +584,6 @@ class Router {
lookup(req: Request, res: Response) {
const handle = this.find(req.method as Method, req.path);

res.req = req;

res.stringify = handle.options.schema.response;

req.params = handle.params;
Expand Down

0 comments on commit 489236a

Please sign in to comment.