Fix CORS configuration to allow requests from Vercel frontend
This commit is contained in:
parent
518aee5df8
commit
1a0c8dd221
17
README.md
17
README.md
@ -184,4 +184,19 @@ Once the application is running, you can access the API documentation at:
|
|||||||
|
|
||||||
## Database
|
## Database
|
||||||
|
|
||||||
The application uses SQLite as the database. The database file is created at `/app/storage/db/db.sqlite`.
|
The application uses SQLite as the database. The database file is created at `/app/storage/db/db.sqlite`.
|
||||||
|
|
||||||
|
## CORS Configuration
|
||||||
|
|
||||||
|
The API has CORS (Cross-Origin Resource Sharing) enabled with the following configuration:
|
||||||
|
|
||||||
|
- Allowed origins:
|
||||||
|
- http://localhost
|
||||||
|
- http://localhost:3000
|
||||||
|
- https://v0-ecommerce-app-build-swart.vercel.app
|
||||||
|
- *
|
||||||
|
|
||||||
|
- Allowed methods: GET, POST, PUT, DELETE, OPTIONS, PATCH
|
||||||
|
- Allowed headers: Content-Type, Authorization, Accept, Origin, X-Requested-With, X-CSRF-Token
|
||||||
|
- Exposed headers: Content-Length
|
||||||
|
- Max age for preflight requests: 600 seconds (10 minutes)
|
@ -23,7 +23,12 @@ class Settings(BaseSettings):
|
|||||||
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||||
|
|
||||||
# CORS settings
|
# CORS settings
|
||||||
CORS_ORIGINS: List[str] = ["*"]
|
CORS_ORIGINS: List[str] = [
|
||||||
|
"http://localhost",
|
||||||
|
"http://localhost:3000",
|
||||||
|
"https://v0-ecommerce-app-build-swart.vercel.app",
|
||||||
|
"*"
|
||||||
|
]
|
||||||
|
|
||||||
# Security settings
|
# Security settings
|
||||||
PASSWORD_HASH_ROUNDS: int = 12
|
PASSWORD_HASH_ROUNDS: int = 12
|
||||||
|
8
main.py
8
main.py
@ -17,10 +17,12 @@ app = FastAPI(
|
|||||||
# Set up CORS
|
# Set up CORS
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["*"],
|
allow_origins=settings.CORS_ORIGINS,
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
|
||||||
allow_headers=["*"],
|
allow_headers=["Content-Type", "Authorization", "Accept", "Origin", "X-Requested-With", "X-CSRF-Token"],
|
||||||
|
expose_headers=["Content-Length"],
|
||||||
|
max_age=600, # 10 minutes cache for preflight requests
|
||||||
)
|
)
|
||||||
|
|
||||||
# Include API router
|
# Include API router
|
||||||
|
Loading…
x
Reference in New Issue
Block a user