fastapi-versioning
fastapi-versioning copied to clipboard
VersionedFastAPI causes all OPTIONS requests to return a 405
Describe the bug
When using VersionedFastAPI all OPTIONS requests return a 405.
app = FastAPI(title='APP NAME')
APP_VERSION = "1.1.1"
app.add_middleware(
CORSMiddleware,
allow_origin_regex='https?://.*',
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*'],
)
app.include_router(api_router_v1_0, prefix=config.API_V1_STR)
app.include_router(api_router_v1_1, prefix=config.API_V1_STR)
app = VersionedFastAPI(app)
To Reproduce Steps to reproduce the behavior:
- initialize app using
VersionedFastAPI - make a request that requires CORS options
- view response details
- returns a 405
Expected behavior Options request to pass as expected
I had to add the middleware after Declaring the VersionedFastAPI. So this should hopefully fix it:
app = FastAPI(title='APP NAME')
APP_VERSION = "1.1.1"
app.include_router(api_router_v1_0, prefix=config.API_V1_STR)
app.include_router(api_router_v1_1, prefix=config.API_V1_STR)
app = VersionedFastAPI(app)
app.add_middleware(
CORSMiddleware,
allow_origin_regex='https?://.*',
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*'],
)