Comparing version 0.14.0 to 0.15.0
@@ -32,5 +32,6 @@ /// <reference types="node" /> | ||
append: (request: Request) => () => void; | ||
custom: (request: http.IncomingMessage, response: http.ServerResponse, next: Function) => void; | ||
constructor(routes: Routes, middlewares?: Middleware[], handleError?: ({ response }: { | ||
response: any; | ||
}) => (error: any) => void, append?: (context: any) => () => void); | ||
}) => (error: any) => void, append?: (context: any) => () => void, custom?: (request: any, response: any, next: any) => void); | ||
use(middleware: Middleware): this; | ||
@@ -37,0 +38,0 @@ add(method: HTTPMethod, path: string, ...fns: [...Middleware[], Handler]): this; |
@@ -80,3 +80,3 @@ "use strict"; | ||
response.statusCode = 500; | ||
}, append = context => () => { }) { | ||
}, append = context => () => { }, custom = (request, response, next) => { next(); }) { | ||
this.middlewares = middlewares; | ||
@@ -89,2 +89,3 @@ this.router = new router_1.Router(); | ||
this.append = append; | ||
this.custom = custom; | ||
// TODO move it to `start` once it's abstracted | ||
@@ -138,6 +139,7 @@ for (const [path, params] of this.routes) { | ||
const pipeline = compose(...this.middlewares)((_) => response_1.NotFound()); | ||
pipeline(context) | ||
const prepend = next => this.custom(request, response, next); | ||
prepend(() => pipeline(context) | ||
.then(core_1.handle(context)) | ||
.then(this.append(context)) | ||
.catch(this.handleError(context)); | ||
.catch(this.handleError(context))); | ||
}) | ||
@@ -144,0 +146,0 @@ .on('error', error => { |
{ | ||
"name": "retes", | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"description": "Typed, Declarative, Data-Driven Routing for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
159338
1362