DEOGEE
Explore posts from serversCors issues only on railway
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));
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));
22 replies