summary refs log tree commit diff
path: root/synapse/http/server.py
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-08-14 11:37:13 +0100
committerKegan Dougal <kegan@matrix.org>2014-08-14 11:37:13 +0100
commit9fd445eb92ed9def98764968a3f3fceb0ae706c9 (patch)
tree29d7e944e7380f5a0396dc7c8913f3224ffc6bd0 /synapse/http/server.py
parentFixed dynamic resource mapping to clobber dummy Resources with the actual des... (diff)
downloadsynapse-9fd445eb92ed9def98764968a3f3fceb0ae706c9.tar.xz
If the web client is enabled, automatically redirect root '/' to the web client path.
Diffstat (limited to 'synapse/http/server.py')
-rw-r--r--synapse/http/server.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 87b4fc8a5f..bad2738bde 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -22,6 +22,7 @@ from synapse.api.errors import cs_exception, CodeMessageException
 from twisted.internet import defer, reactor
 from twisted.web import server, resource
 from twisted.web.server import NOT_DONE_YET
+from twisted.web.util import redirectTo
 
 import collections
 import logging
@@ -159,6 +160,22 @@ class JsonResource(HttpServer, resource.Resource):
         return False
 
 
+class RootRedirect(resource.Resource):
+    """Redirects the root '/' path to another path."""
+
+    def __init__(self, path):
+        resource.Resource.__init__(self)
+        self.url = path
+
+    def render_GET(self, request):
+        return redirectTo(self.url, request)
+
+    def getChild(self, name, request):
+        if len(name) == 0:
+            return self  # select ourselves as the child to render
+        return resource.Resource.getChild(self, name, request)
+
+
 def respond_with_json_bytes(request, code, json_bytes, send_cors=False):
     """Sends encoded JSON in response to the given request.