Skip to content

Commit

Permalink
Добавляет CORS'ы в бэкенд
Browse files Browse the repository at this point in the history
  • Loading branch information
codEnjoyer committed Nov 16, 2023
1 parent 7f49980 commit 7a1886a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
34 changes: 24 additions & 10 deletions backend/src/main.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
from fastapi import FastAPI, APIRouter, status, Depends
from fastapi.responses import RedirectResponse
from fastapi.middleware.cors import CORSMiddleware

from game.levels.router import router as levels_router
from game.modules.router import router as modules_router
from game.map.router import router as map_router
from game.units.tasks.router import router as tasks_router
from game.units.theory.router import router as theory_router

from users.router import router as users_router
from users.tutors.router import router as tutors_router
from users.employees.router import router as employees_router
# from game.levels.router import router as levels_router
# from game.modules.router import router as modules_router
# from game.map.router import router as map_router
# from game.units.tasks.router import router as tasks_router
# from game.units.theory.router import router as theory_router
#
# from users.router import router as users_router
# from users.tutors.router import router as tutors_router
# from users.employees.router import router as employees_router

from auth.router import router as auth_router
from auth.base_config import current_active_user

from settings import Settings
from settings import Settings, FRONT_APP_PORT

app = FastAPI(title="Adaptify")

origins = [
"http://localhost",
f"http://localhost:{FRONT_APP_PORT}",
]

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


def include_routers(*routers: APIRouter) -> None:
for router in routers:
Expand Down
2 changes: 2 additions & 0 deletions backend/src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
SECRET_JWT_KEY = os.environ.get("SECRET_JWT_KEY")

BACK_APP_PORT = os.environ.get("BACK_APP_PORT")
FRONT_APP_PORT = os.environ.get("FRONT_APP_PORT")


class Settings(BaseSettings):
pg_url: ClassVar[PostgresDsn] = f"postgresql+asyncpg://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
secret_jwt: ClassVar[SecretStr] = SECRET_JWT_KEY
backend_port: ClassVar[int] = BACK_APP_PORT
frontend_port: ClassVar[int] = FRONT_APP_PORT

0 comments on commit 7a1886a

Please sign in to comment.