Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CORS checks #969

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/api/code/lacity_data_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
TESTING = config("TESTING", cast=bool, default=False)
STAGE = config("STAGE", default="Local")

# string array of allows client URLs
API_ALLOWED_ORIGINS = config(
"API_ALLOWED_ORIGINS",
default=["http://localhost:3000", "https://*.311-data.org"]
)

# getting database configuration
DB_DRIVER = config("DB_DRIVER", default="postgresql")
DB_HOST = config("DB_HOST", default="localhost")
Expand Down
4 changes: 2 additions & 2 deletions server/api/code/lacity_data_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware

from .config import DEBUG
from .config import DEBUG, API_ALLOWED_ORIGINS
from .models import db
from .routers import (
index, councils, regions, request_types, service_requests, shim, status,
Expand Down Expand Up @@ -45,7 +45,7 @@ def get_app():

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_origins=API_ALLOWED_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down