Cors issues only on railway
My server was working fine and suddenly i started getting cors error "117:1 Access to fetch at 'https://create-video-production.up.railway.app/create-video' from origin 'https://www.shortsauto.ai/' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: 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."
i have this line of code 'app.use(cors());' in my server
The code works fine with no cors issues in other services such as render , it worked fine in railway too but suddenly stopped working
Solution:Jump to solution
you have enabled app sleeping?
if so, the first page will be an error page, the error page of course will not have cors headers so you will get the cors errors.
this is a known issue, until it's fixed, please disable app sleeping....
13 Replies
Project ID:
N/A
N/A
Seems like theres no erros on railway logs
The error is on the browser
const allowedOrigins = ['https://www.shortsauto.ai', 'http://localhost:3000'];
const corsOptions = {
origin: (origin, callback) => {
// Allow requests with no origin (like mobile apps or curl requests)
if (!origin) return callback(null, true);
if (allowedOrigins.includes(origin)) { callback(null, true); // Origin is allowed } else { callback(new Error('Not allowed by CORS')); // Origin is not allowed } }, methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], // Allow specific methods allowedHeaders: ['Content-Type', 'Authorization'], // Specify allowed headers credentials: true, // Include credentials (optional) optionsSuccessStatus: 204, // For legacy browser support }; // Enable CORS with the specified options app.use(cors(corsOptions)); // Handle preflight requests explicitly app.options('*', cors(corsOptions)); I added the code above in my server and it worked and now it stopped working again with the same cors error I refreshed the page and it works now. It keeps fluctuating between working and not working . is it the sleep thats causing the cors error ?
if (allowedOrigins.includes(origin)) { callback(null, true); // Origin is allowed } else { callback(new Error('Not allowed by CORS')); // Origin is not allowed } }, methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], // Allow specific methods allowedHeaders: ['Content-Type', 'Authorization'], // Specify allowed headers credentials: true, // Include credentials (optional) optionsSuccessStatus: 204, // For legacy browser support }; // Enable CORS with the specified options app.use(cors(corsOptions)); // Handle preflight requests explicitly app.options('*', cors(corsOptions)); I added the code above in my server and it worked and now it stopped working again with the same cors error I refreshed the page and it works now. It keeps fluctuating between working and not working . is it the sleep thats causing the cors error ?
Solution
you have enabled app sleeping?
if so, the first page will be an error page, the error page of course will not have cors headers so you will get the cors errors.
this is a known issue, until it's fixed, please disable app sleeping.
Yes i enabled app sleeping . I figured that might be the case.
How can we track the progress of this fix , is there a thread or something with updates about this issue
I have already added a link to this discord thread into our internal issue and thus when it's fixed, I will come back and update you
so no ETA unfortunately
Thank you . Could you also please add my email into your internal issue , just in case i'm not available here
the follow up a manual process at the moment, so it works best for everyone if all I have to do is send a discord message, I would ping you once it's resolved
Noted.
Thank you
no problem, will mark as solved for now
Hello,
We've resolved an issue where apps with longer startup times were showing 502 errors. Apps now have up to 10 seconds to start accepting traffic, thus preventing these error pages from appearing.
You will need to trigger a deployment so that the changes we have made take effect.
cc @DEOGEE