From f4c8252185efada155238d7ad272dac74e04302e Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Sun, 7 Aug 2022 23:15:05 +0300 Subject: [PATCH] Always show server location in ASGI --- sanic/mixins/runner.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sanic/mixins/runner.py b/sanic/mixins/runner.py index 3d2b327d..57387401 100644 --- a/sanic/mixins/runner.py +++ b/sanic/mixins/runner.py @@ -69,6 +69,7 @@ else: class RunnerMixin(metaclass=SanicMeta): _app_registry: Dict[str, Sanic] + asgi: bool config: Config listeners: Dict[str, List[ListenerType[Any]]] state: ApplicationState @@ -525,7 +526,7 @@ class RunnerMixin(metaclass=SanicMeta): ) ) else: - server = "" + server = "ASGI" if self.asgi else "unknown" display = { "mode": " ".join(mode), @@ -571,8 +572,12 @@ class RunnerMixin(metaclass=SanicMeta): @property def serve_location(self) -> str: - server_settings = self.state.server_info[0].settings - return self.get_server_location(server_settings) + try: + server_settings = self.state.server_info[0].settings + return self.get_server_location(server_settings) + except IndexError: + location = "ASGI" if self.asgi else "unknown" + return f"http://<{location}>" @staticmethod def get_server_location(