From d0d0bf80d87db2a12fa6eca10c2081f583f5300d Mon Sep 17 00:00:00 2001 From: Lukasz Dynowski Date: Tue, 31 Mar 2026 19:09:29 +0200 Subject: [PATCH] Fix AsyncAPI build --- .../middleware/websocket_middleware.py | 62 +++++++++---------- src/django/docs/WEBSOCKET.md | 6 +- src/rabbitmq/README.md | 6 +- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/django/app/core/helpers/middleware/websocket_middleware.py b/src/django/app/core/helpers/middleware/websocket_middleware.py index 5c54449..ca2c775 100644 --- a/src/django/app/core/helpers/middleware/websocket_middleware.py +++ b/src/django/app/core/helpers/middleware/websocket_middleware.py @@ -21,6 +21,8 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send): or if the list is not set. The "*" wildcard allows all clients to connect. + NOTE: This middleware is enabled for all Starlette routes. This change fixes the previously non-working SSE endpoint. + Args: scope: The ASGI connection scope dictionary. receive: Awaitable callable to receive events. @@ -29,26 +31,25 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send): Returns: Awaitable: The result of calling the next ASGI app or a 403 response if the origin is not allowed. """ - if scope["type"] == "websocket": - if not self.allow_origins: - response = self.response("Origin not allowed", status_code=403) - return await response(scope, receive, send) + if not self.allow_origins: + response = self.response("Origin not allowed", status_code=403) + return await response(scope, receive, send) - if "*" in self.allow_origins: - return await self.app(scope, receive, send) + if "*" in self.allow_origins: + return await self.app(scope, receive, send) - # Check if the origin is in the allowed origins - headers = Headers(scope=scope) - origin = headers.get("origin") - for host in self.allow_origins: - if host.startswith("*") and host[1:] in origin: - return await self.app(scope, receive, send) + # Check if the origin is in the alloodwed origins + headers = Headers(scope=scope) + origin = headers.get("origin") + for host in self.allow_origins: + if host.startswith("*") and host[1:] in origin: + return await self.app(scope, receive, send) - if host in origin: - return await self.app(scope, receive, send) + if host in origin: + return await self.app(scope, receive, send) - response = self.response("Origin not allowed", status_code=403) - return await response(scope, receive, send) + response = self.response("Origin not allowed", status_code=403) + return await response(scope, receive, send) def response(self, body: str, status_code: int): """ @@ -85,25 +86,24 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send): Returns: Awaitable: The result of calling the next ASGI app or a 403 response if the host is not allowed. """ - if scope["type"] == "websocket": - if not self.allowed_hosts: - response = self.response("Host not allowed", status_code=403) - return await response(scope, receive, send) + if not self.allowed_hosts: + response = self.response("Host not allowed", status_code=403) + return await response(scope, receive, send) - if "*" in self.allowed_hosts: - return await self.app(scope, receive, send) + if "*" in self.allowed_hosts: + return await self.app(scope, receive, send) - # Check if the host is in the allowed hosts - headers = Headers(scope=scope) - for host in self.allowed_hosts: - if host.startswith("*") and host[1:] in headers.get("host"): - return await self.app(scope, receive, send) + # Check if the host is in the allowed hosts + headers = Headers(scope=scope) + for host in self.allowed_hosts: + if host.startswith("*") and host[1:] in headers.get("host"): + return await self.app(scope, receive, send) - if host in headers.get("host"): - return await self.app(scope, receive, send) + if host in headers.get("host"): + return await self.app(scope, receive, send) - response = self.response("Host not allowed", status_code=403) - return await response(scope, receive, send) + response = self.response("Host not allowed", status_code=403) + return await response(scope, receive, send) def response(self, body: str, status_code: int): """ diff --git a/src/django/docs/WEBSOCKET.md b/src/django/docs/WEBSOCKET.md index 54a0de8..daab9bf 100644 --- a/src/django/docs/WEBSOCKET.md +++ b/src/django/docs/WEBSOCKET.md @@ -120,12 +120,12 @@ The generated documentation is available in the _src/django/docs/api/websocket/o cd src/django/docs/api/websocket # Generate HTML documentation using the _asyncapi/cli_ Docker image -docker run --rm -it --user=root \ +docker run --rm -it \ --volume ${PWD}/output:/app/output \ --volume ${PWD}/v1-schema.yaml:/app/asyncapi.yaml \ asyncapi/cli generate fromTemplate /app/asyncapi.yaml \ - @asyncapi/html-template@3.0.0 \ - --force-write --use-new-generator --output /app/output + @asyncapi/html-template \ + --force-write --output /app/output # Serve the generated HTML documentation using the Nginx web server docker run --rm --detach --publish 127.0.0.1:8888:80 \ diff --git a/src/rabbitmq/README.md b/src/rabbitmq/README.md index 8a78194..4a1a543 100644 --- a/src/rabbitmq/README.md +++ b/src/rabbitmq/README.md @@ -389,12 +389,12 @@ The AsyncAPI specification is a standard for describing asynchronous APIs, simil cd src/rabbitmq/2.WorkQueue/docs/api/v1.0.0 # Generate HTML documentation -docker run --rm -it --user=root \ +docker run --rm -it \ --volume ${PWD}/output:/app/output \ --volume ${PWD}/work_queue.yaml:/app/asyncapi.yaml \ asyncapi/cli generate fromTemplate /app/asyncapi.yaml \ - @asyncapi/html-template@3.0.0 \ - --use-new-generator --force-write --output /app/output + @asyncapi/html-template \ + --force-write --output /app/output # Serve documentation with Nginx docker run --rm --detach --publish 127.0.0.1:8888:80 \