CORS backend error

Hi! I have my backend hosted on railway but my frontend on Azure. I have a lot of endpoints on my API, but I'm getting CORS error on websocket. Whenever I try to stablish a connection it gives me this error: Access to XMLHttpRequest at 'https://dev-api-agendai.up.railway.app/issues' from origin 'https://agendai-dev.azurewebsites.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Solution:
Hi! I have my backend hosted on railway but my frontend on Azure. I have a lot of endpoints on my API, but I'm getting CORS error on websocket. Whenever I try to stablish a connection it gives me this error: Access to XMLHttpRequest at 'https://dev-api-agendai.up.railway.app/issues' from origin 'https://agendai-dev.azurewebsites.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource....
Jump to solution
65 Replies
Percy
Percy2y ago
Project ID: cc386d0c-2f7d-465e-97db-3e498cbd5176
jatoboy
jatoboyOP2y ago
cc386d0c-2f7d-465e-97db-3e498cbd5176
jatoboy
jatoboyOP2y ago
HI there Brody! As you can imagine, I already have everything setup in terms of code. I'm looking foward to see if there is any block in railway servers about WEBSOCKET and CORS policy?
Brody
Brody2y ago
railway has full support for websockets, and will not remove any headers
jatoboy
jatoboyOP2y ago
Can you guide me on how to see these details?
Brody
Brody2y ago
network tab in devtools
jatoboy
jatoboyOP2y ago
Thanks Brody, I'll look into it.
Brody
Brody2y ago
<wss://dev-api-agendai.up.railway.app/issues> is not a websocket endpoint though?
jatoboy
jatoboyOP2y ago
Indeed, this is not the websocket endpoint but it's the one that the console is showing. wss://dev-api-agendai.up.railway.app/socket.io/?EIO=4&transport=websocket
jatoboy
jatoboyOP2y ago
Brody
Brody2y ago
looks good, is there a pending network request?
jatoboy
jatoboyOP2y ago
Not that I had notice.
jatoboy
jatoboyOP2y ago
In localhost, isn't everything all right with my headers?
Brody
Brody2y ago
why do you keep showing me the /issues endpoint, it has nothing to do with websockets
jatoboy
jatoboyOP2y ago
I'm sorry, let me show you the error in the console because I'm not sure if the error is with websocket in API or CORS policy.
jatoboy
jatoboyOP2y ago
Brody
Brody2y ago
i do not get these errors when i visit https://agendai-dev.azurewebsites.net/ i see a successful websoscket connection open, and it stays open without issue
jatoboy
jatoboyOP2y ago
What about this error 503?
jatoboy
jatoboyOP2y ago
The 3rd error here on the console, failed 503.
Brody
Brody2y ago
i dont see 503 on my end
jatoboy
jatoboyOP2y ago
Could I guide you to the page where the error happens?
Brody
Brody2y ago
yes please
jatoboy
jatoboyOP2y ago
user: admin1 pass: @admin10
jatoboy
jatoboyOP2y ago
When you log in, you can select the blue button and also one of the gray bellow it.
jatoboy
jatoboyOP2y ago
Like that.
Brody
Brody2y ago
jatoboy
jatoboyOP2y ago
hmmm where did u get this error?
Brody
Brody2y ago
loging in
jatoboy
jatoboyOP2y ago
Can u try again, please?
Brody
Brody2y ago
works
jatoboy
jatoboyOP2y ago
Okay, u need to get to this page:
jatoboy
jatoboyOP2y ago
After these steps
Brody
Brody2y ago
clicking the blue arrow doesnt do anything some loading dots pop up, disapear and nothing happens
jatoboy
jatoboyOP2y ago
Try choosing other GUICHÊS please. Like the third ou fourth.
Brody
Brody2y ago
okay im here
jatoboy
jatoboyOP2y ago
See your name?
Brody
Brody2y ago
i did, but it disapeared before my eyes
jatoboy
jatoboyOP2y ago
Really? So it's empty? Wait a sec
Brody
Brody2y ago
jatoboy
jatoboyOP2y ago
Just a sec I'll create a new one
Brody
Brody2y ago
im getting a bunch of 503 status codes too
jatoboy
jatoboyOP2y ago
Try refreshing this page it should appear another one with your name, and then you can click on ATENDER right in side of it
Brody
Brody2y ago
okay refreshed and no errors so far
Brody
Brody2y ago
jatoboy
jatoboyOP2y ago
Are you here?
Brody
Brody2y ago
no errors
jatoboy
jatoboyOP2y ago
Okay, the error will appear when you click on this stream logo. On the button actually. That has the text EXIBIR NA TV.
Brody
Brody2y ago
Brody
Brody2y ago
no errors
jatoboy
jatoboyOP2y ago
wait whaat it worked with you why? lol
Brody
Brody2y ago
nvm webscoket conn dropped and wont reconnect
jatoboy
jatoboyOP2y ago
https://agendai-dev.azurewebsites.net/tv it should appear here... and it worked for a moment but now I get a bunch of erros too
Brody
Brody2y ago
your app is just very unstable lol, not a railway issue
jatoboy
jatoboyOP2y ago
xD Do u have any clue where this error is coming from?
Brody
Brody2y ago
your unstable code
jatoboy
jatoboyOP2y ago
Okay Brody, thanks for you help I'll look further into it. Thank you a lot.
Brody
Brody2y ago
haha no problem
jatoboy
jatoboyOP2y ago
After all, the server crashed:
jatoboy
jatoboyOP2y ago
🥲
Brody
Brody2y ago
youll have that you can always look at the logs
jatoboy
jatoboyOP2y ago
Looking into it to see any problems.
jatoboy
jatoboyOP2y ago
But I think this prisma error is a generic one or it was given due to connection lost in the app.
Brody
Brody2y ago
just looks like a code issue on your part
Want results from more Discord servers?
Add your server