diff --git a/sanic_ext/config.py b/sanic_ext/config.py index 2fb99eb..f410cb5 100644 --- a/sanic_ext/config.py +++ b/sanic_ext/config.py @@ -10,7 +10,7 @@ from sanic.signals import Event -PRIORITY = 100_000_000 +PRIORITY = -1_000 class Config(SanicConfig): diff --git a/sanic_ext/extensions/http/cors.py b/sanic_ext/extensions/http/cors.py index 23e825f..3346945 100644 --- a/sanic_ext/extensions/http/cors.py +++ b/sanic_ext/extensions/http/cors.py @@ -10,6 +10,8 @@ from sanic.helpers import Default, _default from sanic.log import logger +from sanic_ext.config import PRIORITY + WILDCARD_PATTERN = re.compile(r".*") ORIGIN_HEADER = "access-control-allow-origin" @@ -67,7 +69,7 @@ async def _add_cors_headers(request, response): _add_allow_header(request, response) _add_methods_header(request, response) - @app.before_server_start + @app.before_server_start(priority=PRIORITY) async def _assign_cors_settings(app, _): for group in app.router.groups.values(): _cors = SimpleNamespace() diff --git a/sanic_ext/extensions/http/methods.py b/sanic_ext/extensions/http/methods.py index e0fbf5d..8976e49 100644 --- a/sanic_ext/extensions/http/methods.py +++ b/sanic_ext/extensions/http/methods.py @@ -67,7 +67,7 @@ async def trace_handler(request): ) return raw(message, content_type="message/http") - @app.before_server_start(priority=PRIORITY + 1) + @app.before_server_start(priority=PRIORITY) def _add_handlers(app, _): nonlocal auto_head nonlocal auto_options diff --git a/sanic_ext/extensions/injection/injector.py b/sanic_ext/extensions/injection/injector.py index 24ce171..224bb95 100644 --- a/sanic_ext/extensions/injection/injector.py +++ b/sanic_ext/extensions/injection/injector.py @@ -74,7 +74,7 @@ def _setup_signature_registry( ) -> SignatureRegistry: registry = SignatureRegistry() - @app.listener("before_server_start", priority=PRIORITY) + @app.listener("before_server_start", priority=PRIORITY - 1) async def setup_signatures(app, _): nonlocal registry diff --git a/sanic_ext/extensions/openapi/blueprint.py b/sanic_ext/extensions/openapi/blueprint.py index 19f61ba..c7cdbc6 100644 --- a/sanic_ext/extensions/openapi/blueprint.py +++ b/sanic_ext/extensions/openapi/blueprint.py @@ -9,6 +9,7 @@ from sanic.log import logger from sanic.response import file, html, json +from sanic_ext.config import PRIORITY from sanic_ext.extensions.openapi.builders import ( OperationStore, SpecificationBuilder, @@ -115,7 +116,7 @@ async def spec(request: Request): def openapi_config(request: Request): return json(request.app.config.SWAGGER_UI_CONFIGURATION) - @bp.before_server_start + @bp.before_server_start(priority=PRIORITY) def build_spec(app, loop): specification = SpecificationBuilder() # --------------------------------------------------------------- #