Merge pull request #7 from simonblund/patch-1
Fix issue when returning ReadableStreams and other strange responses
This commit is contained in:
5
index.d.ts
vendored
5
index.d.ts
vendored
@@ -54,6 +54,7 @@ declare class Router {
|
||||
* @property {Object<string, string>} headers Object you can set response headers in
|
||||
* @property {number} status Return status code (default: `204`)
|
||||
* @property {Object<string, string> | 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
|
||||
*/
|
||||
|
||||
5
index.js
5
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
|
||||
module.exports = Router
|
||||
|
||||
Reference in New Issue
Block a user