CORS error in react vite and express
When uploading an image it starts correctly then I get this cors error.
I've this cors settings in vite.config.ts
And this is the cors setup in express
Does anyone know where the problem is ?

22 Replies
its not proxying thorugh your express backend?
It's client side upload.
the server is just the upload router, it looks something like this
you are POSTing directly to uploadthing endpoint though
the issue is that CORS is not enabled in uploadthing, you need to either proxy the upload requests or enable CORS for your endpoint on uploadthing
you mean in my dashboard ?
wait no wtf is going on in the console
ok nvm i am completely wrong
something weird is happening
since I am new to UT, from my understanding is my server creates the presigned URL and gives it back to the client which then begins directly uploading to UT.
I have no cors errors in my backend so I don't know if it's something vite related
withcredentials is false?
yup
how are you making the upload request
since I need auth I have this custom fetch in the options
then generate the react button using
can't include credentials
so how am I supposed to handle auth ?
I am rolling my own auth
better-auth if you know it
no
you generate the presigned url
and then that url is good for one upload
Uploading Files - UploadThing Docs
Uploading files is the first step in the process of uploading files to UploadThing. This page explains the general process of uploading files and how you can use the UploadThing API to upload files. There are two ways to upload files to UploadThing:
there are also no credentials in the
init
object as far as i can see from your consoleSo I should ditch creatRouteHandler and create my own routes ?
That's what was tripping me
the upload starts tho
wdym?
like the uploadrouter?
yes
im not super sure what it does exactly
you still need routes to generate your urls
I was following the examples at
https://github.com/pingdotgg/uploadthing/tree/main/examples/backend-adapters
it seemed like I just use
createRouteHandler
in express server and create the button in React.
but when I didn't override the fetch in the initOpts
I received no headers/cookies so I couldn't authenticateGitHub
uploadthing/examples/backend-adapters at main · pingdotgg/uploadthing
File uploads for modern web devs. Contribute to pingdotgg/uploadthing development by creating an account on GitHub.
yeah idk i cant really comment on backend sorry
Okay, Thank you for your help! ❤️