Comparing version 0.15.0 to 0.16.0
@@ -79,3 +79,3 @@ "use strict"; | ||
constructor(routes, middlewares = [], handleError = ({ response }) => error => { | ||
response.statusCode = 500; | ||
response.writeHead(500).end(error.message); | ||
}, append = context => () => { }, custom = (request, response, next) => { next(); }) { | ||
@@ -139,6 +139,6 @@ this.middlewares = middlewares; | ||
const prepend = next => this.custom(request, response, next); | ||
prepend(() => pipeline(context) | ||
pipeline(context) | ||
.then(core_1.handle(context)) | ||
.then(this.append(context)) | ||
.catch(this.handleError(context))); | ||
.catch(this.handleError(context)); | ||
}) | ||
@@ -145,0 +145,0 @@ .on('error', error => { |
@@ -24,2 +24,4 @@ import { Resource, Response, ResponseBody } from "../types"; | ||
export declare function Conflict(content?: string): Response; | ||
export declare function InternalServerError(content?: string): Response; | ||
export declare function InternalServerError(content?: string, { headers }?: { | ||
headers?: {}; | ||
}): Response; |
@@ -153,6 +153,7 @@ "use strict"; | ||
// | ||
function InternalServerError(content = '') { | ||
function InternalServerError(content = '', { headers = {} } = {}) { | ||
return { | ||
statusCode: 500, | ||
body: content | ||
body: content, | ||
headers | ||
}; | ||
@@ -159,0 +160,0 @@ } |
@@ -8,2 +8,5 @@ /// <reference types="node" /> | ||
export declare type Next = (request?: Request) => Response | Promise<Response>; | ||
interface AnyValue { | ||
[name: string]: any; | ||
} | ||
export interface Request<U = unknown> { | ||
@@ -31,2 +34,3 @@ params: Params; | ||
response: http.ServerResponse; | ||
context: AnyValue; | ||
} | ||
@@ -33,0 +37,0 @@ export declare type ResponseBody = string | object; |
{ | ||
"name": "retes", | ||
"version": "0.15.0", | ||
"version": "0.16.0", | ||
"description": "Typed, Declarative, Data-Driven Routing for Node.js", | ||
@@ -17,3 +17,3 @@ "main": "dist/index.js", | ||
"@types/debug": "^4.1.5", | ||
"@types/node": "^14.14.41", | ||
"@types/node": "^15.3.0", | ||
"ava": "^3.15.0", | ||
@@ -20,0 +20,0 @@ "axios": "^0.21.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
159533
1369