Mason
Mason
RRailway
Created by Mason on 10/15/2023 in #✋|help
Suddenly getting CORS errors sending requests to my backend express server
Hi, I've configured an accepted origin for requests in each of my environments as follows:
app.use(express.json())
app.use(
cors({
origin: process.env.CORS_ALLOWED_ORIGIN,
preflightContinue: true,
})
)
app.use(express.json())
app.use(
cors({
origin: process.env.CORS_ALLOWED_ORIGIN,
preflightContinue: true,
})
)
As you can see the allowed origin for this environment is stored in the variables, e.g. https://myapp-frontend-dev.up.railway.app/ I've double checked this is loaded fine in the backend, and before today wasn't having any issues with this, but now all requests to my backend from the frontend service fail with:
Access to fetch at 'https://myapp-backend-dev.up.railway.app/stripe/getUsage' from origin 'https://myapp-frontend-dev.up.railway.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Access to fetch at 'https://myapp-backend-dev.up.railway.app/stripe/getUsage' from origin 'https://myapp-frontend-dev.up.railway.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
My frontend can no longer interact with the backend at all, including in environments where the code hasn't been touched in days. Anyone aware what could be the issue?
16 replies
RRailway
Created by Mason on 9/29/2023 in #✋|help
Using internal networking to communicate with Websocket
Project ID: 2818bb01-9898-4d1c-8065-06e6404b3ed8 Hi folks, suspect I'm doing something particularly silly, but I have a React app hosted on Railway which connects to a websocket server deployed in the same environment as follows:
let socket = new Websocket("wss://...")
let socket = new Websocket("wss://...")
I notice that when I use the internal networking URL to connect to the websocket server, e.g.
wss://my-websocket-server.railway.internal
wss://my-websocket-server.railway.internal
Intialization fails:
WebSocket connection to 'wss://relevant-transcription-server.railway.internal:8080/' failed:
WebSocket connection to 'wss://relevant-transcription-server.railway.internal:8080/' failed:
Should this be possible? At least locally, if I use the Railway generated public URL of the Websocket server, the Websocket initialization and connection works fine.
81 replies