R
Railway

✋|help

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?
PPercy5/19/2023
Project ID: e4cfbada-ee8d-4956-b396-6eebd2672653
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" 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 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 even if it does return 404, browsers will still throw a cors error, even though the 404 is the real issue 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. 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

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Build CrashingMy build will suddenly crashAfter expiration of credit subscription, all tables were deleted and didn't come back even after payWe have a credit based subscription, the credits expired and we pay today. But all the tables in ourDifferent Environment Variables For Each Domain?Im wondering if theres anyway to have different environment variables for each domain?Vite + Docker deployments to non-Production (staging) environmentsI can build my Vite (React) site locally with Staging Environment configs by using the "vite build -Github repositories are gone!I used to host sites normally previously but now, when I search for github repository there is none,how can i backup my postgresql db?how can i backup my postgresql db?Not able to deploy repo from new serviceI have a monorepo and have multiple deployed services. For some reason, Railway can't find any of myunable to link githubDeployment stuck in "waiting"Project ID: 0c144b75-48db-492d-bb36-ae6352d2ca60Does Railway support ability to pay with Crypto?USDT/USDC stable coins or Bitcoin?deployment angular app from dockerfile and NGIXI'm trying to deploy my angular app with docker and a ngix but I do not have much experience doing iYour subscription is unpaid loopWe cannot get past the subscription is unpaid flag. We have updated our card, attempted to make paymConfiguration Post - Please IgnoreTestingFastAPI - wkhtmltopdfHi there - I have a FastAPI server that requires wkhtmltopdf to run. I added an Aptfile to my repo breact-scripts: Permission deniedI'm trying to mark up the frontend on react.js, but it doesn't work. Writes an error. Project ID: 6How can I create a foreign key with the Postgres GUI in Railway?I don't see an option to connect it with my pkey from another table.PHP 8.0 build "error: attribute 'json' missing"My project ID c0821839-fe34-4bbb-8872-93446a76aec3, Its a CodeIgniter app with uuid is using PHP 8.1Trying to deploy Next js 13 app and its failing?Hey guys, whats the process to deploy a simple Next js app? Version 13. Right now its failing. Is tDeploy successful but old version is servedLooks like the build complete as usual, but when opening the website we still see the old version. File Upload TimeoutHi! I'm running a Django app on a Starter Plan. I want to upload a larger file (70MB) but I get a ti