Skip to content

Commit

Permalink
Reordered middleware and tweaked docstrings
Browse files Browse the repository at this point in the history
Co-authored-by: CasperWA <casper.andersen@epfl.ch>
  • Loading branch information
ml-evs and CasperWA committed Oct 4, 2020
1 parent f9dbb4a commit a23083c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions optimade/server/exception_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def general_exception_handler(request: Request, exc: Exception):
To use these in FastAPI app code:
```python
from fastapi import FastAPI
app = FastAPI()
for exception, handler in OPTIMADE_EXCEPTIONS:
app.add_exception_handler(exception, handler)
```
Expand Down
8 changes: 4 additions & 4 deletions optimade/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def load_entries(endpoint_name: str, endpoint_collection: MongoCollection):
for name, collection in ENTRY_COLLECTIONS.items():
load_entries(name, collection)

# Add required OPTIMADE middleware
# Add CORS middleware first
app.add_middleware(CORSMiddleware, allow_origins=["*"])

# Then add required OPTIMADE middleware
for middleware in OPTIMADE_MIDDLEWARE:
app.add_middleware(middleware)

# Add additional CORS middleware
app.add_middleware(CORSMiddleware, allow_origins=["*"])

# Add exception handlers
for exception, handler in OPTIMADE_EXCEPTIONS:
app.add_exception_handler(exception, handler)
Expand Down
8 changes: 4 additions & 4 deletions optimade/server/main_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@

LOGGER.debug("Done inserting index links!")

# Add required OPTIMADE middleware
# Add CORS middleware first
app.add_middleware(CORSMiddleware, allow_origins=["*"])

# Then add required OPTIMADE middleware
for middleware in OPTIMADE_MIDDLEWARE:
app.add_middleware(middleware)

# Add additional CORS middleware
app.add_middleware(CORSMiddleware, allow_origins=["*"])

# Add exception handlers
for exception, handler in OPTIMADE_EXCEPTIONS:
app.add_exception_handler(exception, handler)
Expand Down
2 changes: 2 additions & 0 deletions optimade/server/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ async def dispatch(self, request: Request, call_next):
To use these in FastAPI app code:
```python
from fastapi import FastAPI
app = FastAPI()
for middleware in OPTIMADE_MIDDLEWARE:
app.add_middleware(middleware)
```
Expand Down

0 comments on commit a23083c

Please sign in to comment.