Skip to content

Commit

Permalink
Add CORS middleware to support requests from other origins
Browse files Browse the repository at this point in the history
Rename existing (incorrectly-named) middleware module to make space!
  • Loading branch information
mfisher87 committed Jul 16, 2024
1 parent 9462632 commit 6e40b87
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/aross_stations_db/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from aross_stations_db.api.v1.routes import router as v1_router

Expand All @@ -9,6 +10,13 @@
),
)
api.include_router(v1_router, prefix="/v1", tags=["v1"])
api.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)


@api.get("/")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/aross_stations_db/api/v1/climatology.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from geoalchemy2 import WKTElement
from sqlalchemy.orm import Session

from aross_stations_db.api.dependencies import get_db_session
from aross_stations_db.api.v1.output import (
ClimatologyJsonElement,
climatology_query_results_to_json,
)
from aross_stations_db.middleware import get_db_session
from aross_stations_db.query import climatology_query

router = APIRouter()
Expand Down
2 changes: 1 addition & 1 deletion src/aross_stations_db/api/v1/stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from geoalchemy2 import WKTElement
from sqlalchemy.orm import Session

from aross_stations_db.api.dependencies import get_db_session
from aross_stations_db.api.v1.output import (
StationsGeoJson,
stations_query_results_to_geojson,
)
from aross_stations_db.middleware import get_db_session
from aross_stations_db.query import stations_query

router = APIRouter()
Expand Down
2 changes: 1 addition & 1 deletion src/aross_stations_db/api/v1/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from geoalchemy2 import WKTElement
from sqlalchemy.orm import Session

from aross_stations_db.api.dependencies import get_db_session
from aross_stations_db.api.v1.output import (
TimeseriesJsonElement,
timeseries_query_results_to_json,
)
from aross_stations_db.middleware import get_db_session
from aross_stations_db.query import timeseries_query

router = APIRouter()
Expand Down

0 comments on commit 6e40b87

Please sign in to comment.