R
Railway2mo ago
DEOGEE

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:
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....
Jump to solution
13 Replies
Percy
Percy2mo ago
Project ID: N/A
DEOGEE
DEOGEEOP2mo ago
N/A
DEOGEE
DEOGEEOP2mo ago
Seems like theres no erros on railway logs
No description
DEOGEE
DEOGEEOP2mo ago
The error is on the browser
No description
DEOGEE
DEOGEEOP2mo ago
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 ?
Solution
Brody
Brody2mo ago
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.
DEOGEE
DEOGEEOP2mo ago
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
Brody
Brody2mo ago
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
DEOGEE
DEOGEEOP2mo ago
Thank you . Could you also please add my email into your internal issue , just in case i'm not available here
Brody
Brody2mo ago
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
DEOGEE
DEOGEEOP2mo ago
Noted. Thank you
Brody
Brody2mo ago
no problem, will mark as solved for now
Brody
Brody5d ago
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
Want results from more Discord servers?
Add your server