Getting CORS error with tRPC express adapter, locally
I've got a Vite + tRPC backend (same repo) that I'm struggling to get queries from.
I'm just getting 'Failed to Fetch' on the UI and Network says it's a Cors error.
Here's my trpcClient
and my Express setup on the server
I've also just tried -- I had ViteExpress up and running a year ago and that worked fine though.
I'm running this locally so I don't understand why CORS would be an issue.
As you can see I've added the CORS info as seen here: https://trpc.io/docs/client/cors
Any ideas?
Send cookies cross-origin | tRPC
If your API resides on a different origin than your front-end and you wish to send cookies to it, you will need to enable CORS on your server and send cookies with your requests by providing the option {credentials: "include"} to fetch.
Solution:Jump to solution
I realized that I could just run the tRPC server and that also runs the client somehow — so no need for different ports and causing cors issues.
1 Reply
Solution
I realized that I could just run the tRPC server and that also runs the client somehow — so no need for different ports and causing cors issues.