Skip to content

Commit

Permalink
CORS settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dyakovri committed Apr 25, 2024
1 parent d11f04d commit 6ba9686
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions aciniformes_backend/routes/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi_sqlalchemy import DBSessionMiddleware

from aciniformes_backend.settings import get_settings
Expand All @@ -20,3 +21,11 @@
db_url=str(get_settings().DB_DSN),
engine_args={"pool_pre_ping": True, "isolation_level": "AUTOCOMMIT"},
)

app.add_middleware(
CORSMiddleware,
allow_origins=settings.CORS_ALLOW_ORIGINS,
allow_credentials=settings.CORS_ALLOW_CREDENTIALS,
allow_methods=settings.CORS_ALLOW_METHODS,
allow_headers=settings.CORS_ALLOW_HEADERS,
)
7 changes: 7 additions & 0 deletions aciniformes_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@

class Settings(BaseSettings):
DB_DSN: PostgresDsn = 'postgresql://postgres@localhost:5432/postgres'

CORS_ALLOW_ORIGINS: list[str] = ['*']
CORS_ALLOW_CREDENTIALS: bool = True
CORS_ALLOW_METHODS: list[str] = ['*']
CORS_ALLOW_HEADERS: list[str] = ['*']

BACKEND_URL: HttpUrl = "http://127.0.0.1:8000"
FETCHERS_UPDATE_DELAY_IN_SECONDS: int = 10
model_config = ConfigDict(case_sensitive=True, env_file=".env", extra="ignore")



@lru_cache()
def get_settings():
return Settings()

0 comments on commit 6ba9686

Please sign in to comment.