router and fix backend cors
This commit is contained in:
@@ -42,11 +42,17 @@ class RefreshToken(BaseModel):
|
||||
expire_days: int
|
||||
|
||||
|
||||
class CorsSettings(BaseModel):
|
||||
production: str
|
||||
local: list[str] = ["http://localhost:5173", "http://localhost:5174"]
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
api: ApiPrefix = ApiPrefix()
|
||||
db: DbSettings = DbSettings()
|
||||
access_token: AccessToken
|
||||
refresh_token: RefreshToken
|
||||
cors_settings: CorsSettings
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env", env_file_encoding="utf-8", env_nested_delimiter="__"
|
||||
)
|
||||
|
||||
11
src/main.py
11
src/main.py
@@ -5,10 +5,21 @@ import uvicorn
|
||||
from fastapi import FastAPI
|
||||
|
||||
sys.path.append(str(Path(__file__).parent.parent))
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from src.api import router
|
||||
from src.core.settings import settings
|
||||
|
||||
app = FastAPI(title="Task&Coffee")
|
||||
app.include_router(router=router)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.cors_settings.local + [settings.cors_settings.production],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run("src.main:app", port=8000, log_level="info", reload=True)
|
||||
|
||||
Reference in New Issue
Block a user