diff --git a/index.d.ts b/index.d.ts index 4f3432d..049180b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -54,6 +54,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 @@ -291,6 +292,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 */ diff --git a/index.js b/index.js index 2280a98..7f9d761 100644 --- a/index.js +++ b/index.js @@ -359,6 +359,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 @@ -370,4 +373,4 @@ class Router { } } -module.exports = Router \ No newline at end of file +module.exports = Router