CORS configuration
📖 Scenario: You are building a Rails API that will be accessed by a frontend app running on a different domain. To allow the frontend to communicate with your API, you need to configure CORS (Cross-Origin Resource Sharing) properly.
🎯 Goal: Configure CORS in a Rails application to allow requests from the frontend domain http://localhost:3000.
📋 What You'll Learn
Create a new initializer file for CORS configuration
Set the allowed origin to
http://localhost:3000Allow HTTP methods GET, POST, and OPTIONS
Allow headers
Content-Type and Authorization💡 Why This Matters
🌍 Real World
Many web apps have frontend and backend on different domains or ports. CORS configuration allows the frontend to safely access backend APIs.
💼 Career
Backend developers often configure CORS to enable frontend apps to communicate with APIs securely and correctly.
Progress0 / 4 steps