T
Join ServertRPC
❓-help
tRPC doesn't support redirect
I use tRPC & @trpc/server/adapters/express.
procdure.query({ctx: { res }} => {
res.redirect('xxx')
})
this will stop node process and some errors like:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client.
But if I just use expressjs,it does not happen.
procdure.query({ctx: { res }} => {
res.redirect('xxx')
})
this will stop node process and some errors like:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client.
But if I just use expressjs,it does not happen.
You shouldn't do this, tRPC is not a http server, it's an abstraction which can (but doesn't have to) live inside one
If you want redirects, do it on the frontend in response to state changes, or use a http server for those endpoints
I will try to solve it like
1. express router + tRPC caller
2. try catch in trpc procedure that redirect
1. express router + tRPC caller
2. try catch in trpc procedure that redirect
It works well using the first method.
The NO.2 remains the same error too.
The NO.2 remains the same error too.