ā Cors Policy Error
When ever my front-end tries to communicate with my back-end I receive this error, any ideas why?
https://cdn.discordapp.com/attachments/1136302991666843680/1146527808072454144/image.png
42 Replies
Yes. Your frontend isnt running at the same host/port as the backend, and you have not disabled CORS
Yes, so in that case should I disable it or is there any other solution
You could configure CORS to allow the frontend specifically, and maybe run that configuration only in development
you dont want a CORS policy that allows a "localhost:xxxx" in production š
hmm why would that be? port of frontend shouldnt change
also if I can allow that in development only what would you suggest for prod
did you miss the "in production" part?
well I dont know how you plan on hosting this in production
if the FE runs on a different host than your BE, you'll need to have a CORS policy for that
I'm hoping its obvious why you dont want to allow
localhost
in production...No it isn't obvious, and no I didn't miss the in-production part, thats why i specifically asked what you'd do for a production scenario
Then I suggest you go read up on what CORS is
because if its not obvious, you don't understand CORS
You do realise this is a support server right
Sure. Doesn't mean I have to explain everything.
Okay, sounds great, anyway, I asked what to do in a production scenario
And its not a support server as in "ask questions, get code"
its "ask questions, get information"
You need to understand what purpose CORS has and what it does and how it works to be able to configure a suitable policy.
Your anwser contains nothing
This is not an anwser
This is just "erm go look it up"
Pobiega
You could configure CORS to allow the frontend specifically, and maybe run that configuration only in development
Quoted by
<@105026391237480448> from #Cors Policy Error (click here)
React with ā to remove this embed.
Pobiega
if the FE runs on a different host than your BE, you'll need to have a CORS policy for that
Quoted by
<@105026391237480448> from #Cors Policy Error (click here)
React with ā to remove this embed.
These are answers.
I'm not going to write the code for you.
or as I previously mentioned, disable CORS
thats also an option, still
auth not working? disable auth š
Explain what CORS is to me, right now.
and how it works
are you feeling okay
š
equating it to auth is an apples to oranges of major proportions lol
"Explain what CORS is to me, right now." š¤
right neow
Yes. Prove to me that you know what it is and how it works
LMAOOOOOOOOOOOO
so we can continue to solve your issue
because unless you are willing to learn, we can't
but just fyi, its very common to disable cors during development and run a strict policy in production (assuming this is a private/internal API meant for your frontend and your frontend only)
there are ofc still ways to get around it, but at least someone else cant make an alternate frontend without also making a backend
Yeah I never asked for development did I
But your screenshot is clearly from development
since the url is localhost
man im gonna breaking my head against a wall in a sec š
read this
please
read it clearly
Are you actually blind?
I've said TWICE now what you should do for prod
https://discord.com/channels/143867839282020352/1146535228014330046/1146541102309052556
run a strict policy in production (assuming this is a private/internal API meant for your frontend and your frontend only)
Pobiega
but just fyi, its very common to disable cors during development and run a strict policy in production (assuming this is a private/internal API meant for your frontend and your frontend only)
Quoted by
<@105026391237480448> from #Cors Policy Error (click here)
React with ā to remove this embed.
Alright cool,
is fine?
remove the
SetIsOriginAllowed
part
that essentially negates the WithOrigins
since you are giving it a function that returns true for any and all origins
in effect, it would disable CORSalright i see
ty
gonna test
note that if you specify https, it will require https
if you want both to be fine, you need to give it both
also, this adds the policy, you also need to apply the cors middleware with
UseCors
like soAlr do that thats fine yes
yup
Fixed, sorry bout any toxic messages thanks for the help
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.