From 847cd58bb67c68a598463c249607213f83e0da35 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 27 Jun 2024 20:44:22 +0200 Subject: [PATCH] raise RuntimeError if middleware stack has already been created when initialiazing StacApi --- stac_fastapi/api/stac_fastapi/api/app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stac_fastapi/api/stac_fastapi/api/app.py b/stac_fastapi/api/stac_fastapi/api/app.py index b4f5125f0..44a55764f 100644 --- a/stac_fastapi/api/stac_fastapi/api/app.py +++ b/stac_fastapi/api/stac_fastapi/api/app.py @@ -478,6 +478,9 @@ def __attrs_post_init__(self): self.app.openapi = self.customize_openapi # add middlewares + if self.middlewares and self.app.middleware_stack is not None: + raise RuntimeError("Cannot add middleware after an application has started") + for middleware in self.middlewares: self.app.user_middleware.insert(0, middleware)