nebius/SWE-bench-extra huggingface dataset:
Repository: opsdroid/opsdroid

Issue:
Add a config option to disable registering a route for /
In the web server by default a route is registered for the base / path. This should be configurable in case a user wants to register their own.

Comments:

Patch:
diff --git a/opsdroid/configuration/example_configuration.yaml b/opsdroid/configuration/example_configuration.yaml
index e73909f..c7e468d 100644
--- a/opsdroid/configuration/example_configuration.yaml
+++ b/opsdroid/configuration/example_configuration.yaml
@@ -37,6 +37,7 @@ welcome-message: true
 ## Configure the web server
 # web:
 #   host: '127.0.0.1'
+#   disable_web_index_handler_in_root: true
 #   port: 8080
 #   ssl:
 #     cert: /path/to/cert.pem
diff --git a/opsdroid/web.py b/opsdroid/web.py
index 1cb3cd3..00baa8a 100644
--- a/opsdroid/web.py
+++ b/opsdroid/web.py
@@ -34,8 +34,10 @@ class Web:
         self.web_app = web.Application()
         self.runner = web.AppRunner(self.web_app)
         self.site = None
-        self.web_app.router.add_get("/", self.web_index_handler)
-        self.web_app.router.add_get("", self.web_index_handler)
+        if not self.config.get("disable_web_index_handler_in_root", False):
+            self.web_app.router.add_get("/", self.web_index_handler)
+            self.web_app.router.add_get("", self.web_index_handler)
+
         self.web_app.router.add_get("/stats", self.web_stats_handler)
         self.web_app.router.add_get("/stats/", self.web_stats_handler)
 


Test patch:
diff --git a/opsdroid/tests/test_web.py b/opsdroid/tests/test_web.py
index b190dfb..4112d8a 100644
--- a/opsdroid/tests/test_web.py
+++ b/opsdroid/tests/test_web.py
@@ -38,6 +38,24 @@ async def test_web_get_host(opsdroid):
     assert app.get_host == "127.0.0.1"
 
 
+async def test_web_disable_web_index_handler_in_root(opsdroid):
+    """Check disabling of web index handler in root."""
+    opsdroid.config["web"] = {"disable_web_index_handler_in_root": True}
+    app = web.Web(opsdroid)
+    canonicals = [resource.canonical for resource in app.web_app._router.resources()]
+    assert "/" not in canonicals
+
+    opsdroid.config["web"] = {"disable_web_index_handler_in_root": False}
+    app = web.Web(opsdroid)
+    canonicals = [resource.canonical for resource in app.web_app._router.resources()]
+    assert "/" in canonicals
+
+    opsdroid.config["web"] = {}
+    app = web.Web(opsdroid)
+    canonicals = [resource.canonical for resource in app.web_app._router.resources()]
+    assert "/" in canonicals
+
+
 async def test_web_get_ssl(opsdroid):
     """Check the host getter."""
     opsdroid.config["web"] = {}