Skip to content

Commit

Permalink
Merge pull request #90 from QActf/fix/cors
Browse files Browse the repository at this point in the history
Добавлен CORS
  • Loading branch information
kokhlo authored Jul 10, 2024
2 parents 6951f42 + e1b82e5 commit a74fa26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Settings(BaseSettings):
EMAIL_USE_TLS: bool = True
# ================================

host: str = 'localhost'

class Config:
env_file = 'infra/.env'

Expand Down
13 changes: 13 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI, applications
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.docs import get_swagger_ui_html
from sqladmin import Admin

Expand Down Expand Up @@ -26,6 +27,18 @@ def swagger_monkey_patch(*args, **kwargs):

app = FastAPI(title=settings.app_title)

origins = [
f'http://{settings.host}'
]

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*']
)

app.include_router(main_router)

authentication_backend = AdminAuth(secret_key=settings.secret)
Expand Down

0 comments on commit a74fa26

Please sign in to comment.