CORS Error

SSankalan5/19/2023
I am encountering CORS error from react frontend after I deployed my Spring boot backend to Railway, although the same code is working from default spring boot route "localhost:8080". The deployed backend is working fine during API testing using Postman. How to solve that?
SSankalan5/19/2023
project ID : e4cfbada-ee8d-4956-b396-6eebd2672653
Bbrody5/19/2023
properly apply the cors settings
SSankalan5/19/2023
I did, the backend is working fine locally with CrossOrigin enabled.
Bbrody5/19/2023
what status code do you get when accessing the url from the browser
SSankalan5/19/2023
No status code, I get the message "Access-Control-Allow-Origin" blocked by "https://newsflash-backend-production.up.railway.app"
SSankalan5/19/2023
in console
Bbrody5/19/2023
please tell me the status code
SSankalan5/19/2023
I didn't get any status code, the deployed project is working fine from postman api testing.
FFinn5/19/2023
i suppose there wont be any as the request is blocked by the browser
SSankalan5/19/2023
it was 200 ok
FFinn5/19/2023
in anycase you need to set cors headers correctly
FFinn5/19/2023
probbaly the preflight request yes
Bbrody5/19/2023
well what i was getting at is that maybe it was returning 404, and the cors headers wouldn't be present on a 404 response, so cors might not actaully be the issue
Bbrody5/19/2023
even if it does return 404, browsers will still throw a cors error, even though the 404 is the real issue
Bbrody5/19/2023
but i see that you just said it returned a 200 code, then yes you need to set your cors headers correctly
SSankalan5/19/2023
But it shouldn't. In the backend I have used Spring Security, so it may return 403 unauthorized on undefined endpoints(which it is), but the defined ones are working correctly through API testing, but once I try to connect from my React frontend, it isn't working and throwing the CORS error.
Bbrody5/19/2023
as we have both said:
you need to set cors headers correctly
SSankalan5/19/2023
The same CORS headers seem to be working on localhost. But I will check again and get back to you. Is there any possible reason why it works locally but not after deployment?
Bbrody5/19/2023
it would be a code issue, not an issue with the platform
SSankalan5/19/2023
Thanks a lot, both of you. I will look into that.
SSankalan5/19/2023
I have solved the issue. I missed to put "/api/v1" in the deployed backend URL as defined in my application. How do I close this issue?
Bbrody5/19/2023
i will mark as solved
SSankalan5/19/2023
Thanks. It was very silly me!
Bbrody5/19/2023
no problem