Replace resolveHTTPResponse with nodeHTTPRequestHandler.
add a test for a POST request using the body to test the body is handles correctly.
nodeHTTPRequestHandler takes care of the headers which means we wont have to handle that in this middleware. It also handles additional things that this middleware is not currently handling. It calls resolveHTTPResponse (as this middleware currently does) under the hood. It is used by the first party express, nest, and standalone (node's http package) adapaters.
There are some potential downsides - in particular that it calls res.end(). This means we cant modify the responds after calling it. We also dont have access to the response of resolveHTTPResponse as we currently do. Additionally it appears to have some logic that assumes a default status of 200, whereas the default status of koa is 404 (https://github.com/trpc/trpc/blob/abc941152b71ff2d68c63156eb5a142174779261/packages/server/src/adapters/node-http/nodeHTTPRequestHandler.ts#L63). At the moment I think these can be worked around but if that turns out not to be the case then then the other option is to use resolveHTTPResponse and re-implement the parts of nodeHTTPRequestHandler that we need. Or, see about making changes to nodeHTTPRequestHandler in tRPC (such as overriding the default status code).
resolveHTTPResponse
withnodeHTTPRequestHandler
.nodeHTTPRequestHandler
takes care of the headers which means we wont have to handle that in this middleware. It also handles additional things that this middleware is not currently handling. It callsresolveHTTPResponse
(as this middleware currently does) under the hood. It is used by the first party express, nest, and standalone (node's http package) adapaters.There are some potential downsides - in particular that it calls
res.end()
. This means we cant modify the responds after calling it. We also dont have access to the response ofresolveHTTPResponse
as we currently do. Additionally it appears to have some logic that assumes a default status of200
, whereas the default status of koa is 404 (https://github.com/trpc/trpc/blob/abc941152b71ff2d68c63156eb5a142174779261/packages/server/src/adapters/node-http/nodeHTTPRequestHandler.ts#L63). At the moment I think these can be worked around but if that turns out not to be the case then then the other option is to useresolveHTTPResponse
and re-implement the parts ofnodeHTTPRequestHandler
that we need. Or, see about making changes tonodeHTTPRequestHandler
in tRPC (such as overriding the default status code).