Skip to content

Commit

Permalink
Fix backend cors
Browse files Browse the repository at this point in the history
  • Loading branch information
phyeony committed Dec 8, 2022
1 parent 8ee4592 commit b33987c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
from . import airbnb_router
import os

FRONTEND_DOMAIN_NAME = os.getenv("FRONTEND_DOMAIN_NAME", "localhost")
FRONTEND_PORT = os.getenv("FRONTEND_PORT","3000")
FRONTEND_DOMAIN_NAME = os.getenv("FRONTEND_DOMAIN_NAME", None)

app = FastAPI()

origins = [
f"http://{FRONTEND_DOMAIN_NAME}:{FRONTEND_PORT}",
f"{FRONTEND_DOMAIN_NAME}:{FRONTEND_PORT}"
"http://localhost:3000",
"localhost:3000"
]

if FRONTEND_DOMAIN_NAME is not None:
origins.append(f'https://{FRONTEND_DOMAIN_NAME}')

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
Expand All @@ -21,4 +23,4 @@
allow_headers=["*"]
)

app.include_router(airbnb_router.router, prefix="/api")
app.include_router(airbnb_router.router, prefix="/api")

0 comments on commit b33987c

Please sign in to comment.