How to get Caddy, React, and Express to play nice with each other?

So essentially I have a bare minimal application that uses Caddy for reverse proxying, React JS as a frontend, and a Node / Express backend that I would like to deploy to Railway. I am using Dockerfiles for each service as this is a requirement for a future project. The current issue I am running into is probably a noob-level question but I am getting a: CORS header ‘Access-Control-Allow-Origin’ missing error. I did make sure to add cors in the server.js file:
app.use(cors())
app.use(cors())
Also, an aside, I made sure to run this code as per the common errors documentation page for Railway:
app.listen(port, "0.0.0.0", () =>
{
console.log(`listening on port ${port}`)
})
app.listen(port, "0.0.0.0", () =>
{
console.log(`listening on port ${port}`)
})
Here is the project link: invite
Railway
Railway
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
Solution:
The private network is IPv6 only so your application needs to bind to ::
Jump to solution
6 Replies
Percy
Percy2mo ago
Project ID: bd9d2446-119b-4082-a16d-a0e471fa974d
JeffPeterson
JeffPetersonOP2mo ago
bd9d2446-119b-4082-a16d-a0e471fa974d
JeffPeterson
JeffPetersonOP2mo ago
Navigating to the Frontend: https://railway-deployment-testing.up.railway.app/test After navigating to the Frontend, there is a button which requests some API. Here is a simple GET endpoint in the Express backend: /api/v1/helloWorld That endpoint will throw the CORS error from the React application. Currently, the backend service is unexposed publicly and I intend to only use internal networking. However, I did test that the backend service works when it has its own exposed domain.
Railway Deployment Testing
Web site created using create-react-app
Solution
Brody
Brody2mo ago
The private network is IPv6 only so your application needs to bind to ::
JeffPeterson
JeffPetersonOP2mo ago
@Brody You're amazing! Thanks that was all it was.
Brody
Brody2mo ago
no problem!
Want results from more Discord servers?
Add your server