From fa2e293dda14870d5bcc6ef2cd81646be86d4e5f Mon Sep 17 00:00:00 2001 From: Simon Blomsterlund Date: Sun, 7 Nov 2021 23:14:12 +0200 Subject: [PATCH 1/2] Fix issue when returning ReadableStreams and other strange responses --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3c10453..225022d 100644 --- a/index.js +++ b/index.js @@ -358,6 +358,9 @@ class Router { res.headers['Content-Type'] = 'application/json' res.body = JSON.stringify(res.body) } + if(res.response){ + return res.response + } return new Response(res.body, { status: res.status || (res.body ? 200 : 204), headers: res.headers @@ -369,4 +372,4 @@ class Router { } } -module.exports = Router \ No newline at end of file +module.exports = Router From f6c7316e093546194b6c627726881d3a303125fc Mon Sep 17 00:00:00 2001 From: Simon Blomsterlund Date: Sun, 7 Nov 2021 23:22:18 +0200 Subject: [PATCH 2/2] Fix the ts object --- index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.d.ts b/index.d.ts index 0b2a94e..c7f1299 100644 --- a/index.d.ts +++ b/index.d.ts @@ -53,6 +53,7 @@ declare class Router { * @property {Object} headers Object you can set response headers in * @property {number} status Return status code (default: `204`) * @property {Object|string} body Either an `object` (will be converted to JSON) or a string + * @property {Response} response A response object that is to be returned, this will void all other res properties and return this as is. */ /** * Next Function @@ -290,6 +291,10 @@ type RouterResponse = { * Return status code (default: `204`) */ status: number + /** + * A response object to be directly returned to the client + */ + response: Response /** * Either an `object` (will be converted to JSON) or a string */