question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`nodeHTTPRequestHandler` stripping out headers, body, and middlewares with Fastify

See original GitHub issue

Hello, we’ve been trying out TRPC on professional projects with Fastify.

We noticed the requestHandler or nodeHTTPRequestHandler is using reply.raw skipping all middleware-defined headers and functionalities including CORS making it unfortunately unusable for production.

according to https://www.fastify.io/docs/latest/Reference/Reply/#raw

.raw
This is the http.ServerResponse from Node core. Whilst you are using the Fastify Reply object, the use of Reply.raw functions is at your own risk as you are skipping all the Fastify logic of handling the HTTP response. e.g.:

as shown on #524

await nodeHTTPRequestHandler({
        req: req.raw,
        res: reply.raw, <----- HERE
        router,
        createContext,
        path: (req.params as any).path,
      });

how can we help ?

thank you

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
KATTcommented, Jan 17, 2022

I see. It seems to me like we should provide a lower level primitive for adapters, where the consumer control the flow of the output rather than tRPC doing res directly.

I’ll have a look at this in the next few weeks, for now, shim res as you’re doing. Great that you found a workaround.

0reactions
github-actions[bot]commented, Oct 4, 2022

This issue has been locked because it had no new activity for 14 days. If you are running into a similar issue, please create a new issue. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Can't set headers after they are sent to the client
When the server gets a request, it iterates over the stack, calling the (request, response, next) method. The problem is, if in one...
Read more >
Build a CRUD API with Fastify - DEV Community ‍ ‍
Hello everyone, in this article we are going to build a NodeJS CRUD API with Fastify. Fastify is a NodeJS framework for building...
Read more >
Proposal: remove request/reply and expose just context #169
Because the actual Fastify request object does not contain the headers of the request. In this way we can also fix the tricky...
Read more >
How to Migrate Your App from Express to Fastify - SitePoint
This middleware function is built in to Express. It handles parsing JSON request bodies. cors. This middleware helps us add CORS headers to...
Read more >
Forget Express.js — opt for these alternatives instead
If you're working on a new project written in Node that acts as a web server, don't default to the familiar Express.js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found