8 months ago
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
0 Replies
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 refreshed the page and it works now. It keeps fluctuating between working and not working . is it the sleep thats causing the cors error ?
8 months 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.
How can we track the progress of this fix , is there a thread or something with updates about this issue
8 months 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
8 months ago
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
8 months 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
8 months ago
no problem, will mark as solved for now
6 months 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.
6 months ago
cc @DEOGEE