How to add CORS headers to API responses?
Specifically I'm looking to use the better-auth API inside my server and it is missing the header to allow credentials.
I'm not sure how the other CORS headers get added to the response. It looks like the OPTIONS requests don't make it to the API handler. Similar Github issue:
https://github.com/TanStack/router/issues/4043
GitHub
Missing HTTP response headers in OPTIONS requests · Issue #4043 ·...
Which project does this relate to? Start Describe the bug When defining a handler for OPTIONS requests in an API router and adding custom headers (e.g., CORS headers), the headers won't find th...
1 Reply
rare-sapphireOP•5mo ago
I figured it out. I was able to find code that was already adding some CORS headers in
node_modules/@tanstack/react-start-config/node_modules/vinxi/node_modules/vite/dist/node/chunks/dep-M1IYMR16.js
. Tracing that back, I added server: { cors: { credentials: true } }
to the vite block in app.config.ts