Skip to content

Commit

Permalink
Update changes for fastapi 0.110.0
Browse files Browse the repository at this point in the history
Signed-off-by: tangy5 <[email protected]>
  • Loading branch information
tangy5 committed Apr 5, 2024
1 parent 4dda1bb commit 227ac01
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion monailabel/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os
import pathlib

from fastapi import FastAPI
from fastapi import FastAPI, Request
from fastapi.middleware import Middleware
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.docs import get_swagger_ui_html
Expand All @@ -37,6 +37,15 @@
wsi_infer,
)
from monailabel.interfaces.utils.app import app_instance, clear_cache
from starlette.middleware.base import BaseHTTPMiddleware

class TrailingSlashMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next):
path = str(request.url.path)
new_path = f"/{path}" if not path.startswith('//') else path
request.scope['path'] = new_path
response = await call_next(request)
return response

origins = [str(origin) for origin in settings.MONAI_LABEL_CORS_ORIGINS] if settings.MONAI_LABEL_CORS_ORIGINS else ["*"]
print(f"Allow Origins: {origins}")
Expand All @@ -56,6 +65,7 @@
)
],
)
app.add_middleware(TrailingSlashMiddleware)

static_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "endpoints", "static")
project_root_absolute = pathlib.Path(__file__).parent.parent.resolve()
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ install_requires =
uvicorn==0.21.1
pydantic>=1.10.7
python-dotenv==1.0.0
fastapi==0.95.0
python-multipart==0.0.6
fastapi==0.110.0
python-multipart==0.0.9
requests-toolbelt==0.10.1
httpx==0.23.3
schedule==1.1.0
Expand Down

0 comments on commit 227ac01

Please sign in to comment.