Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
restore RootRedirect and use STATIC_PREFIX as URL for the homepage
Browse files Browse the repository at this point in the history
somehow this introduced the bug that synapse tried to handle all URL's
to be relative to STATIC_PREFIX so all endpoints got not handled
any longer. This commit introduces a redirect to `/_matrix/static` where
the homepage gets automatically served to circumvent this bug.
  • Loading branch information
krombel committed Nov 13, 2017
1 parent 01c83e6 commit ba0c18e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
13 changes: 7 additions & 6 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from synapse.federation.transport.server import TransportLayerServer
from synapse.module_api import ModuleApi
from synapse.http.additional_resource import AdditionalResource
from synapse.http.server import RootRedirect
from synapse.http.site import SynapseSite
from synapse.metrics import register_memory_metrics
from synapse.metrics.resource import METRICS_PREFIX, MetricsResource
Expand Down Expand Up @@ -92,12 +93,7 @@ def _listener_http(self, config, listener_config):
handler = handler_cls(config, module_api)
resources[path] = AdditionalResource(self, handler.handle_request)

# redirect old webclients to root
resources[WEB_CLIENT_PREFIX] = Redirect("/")

root_resource = File(
os.path.join(os.path.dirname(synapse.__file__), "static")
)
root_resource = RootRedirect(STATIC_PREFIX)

root_resource = create_resource_tree(resources, root_resource)

Expand Down Expand Up @@ -140,6 +136,11 @@ def _configure_named_resource(self, name, compress=False):
dict[str, Resource]: map from path to HTTP resource
"""
resources = {}
if name == "webclient":
# redirect old webclients to root
logger.warn("DEPRECATED: Handling of %s got removed from synapse. Please unconfigure it", WEB_CLIENT_PREFIX)
resources[WEB_CLIENT_PREFIX] = Redirect(STATIC_PREFIX)

if name == "client":
client_resource = ClientRestResource(self)
if compress:
Expand Down
17 changes: 17 additions & 0 deletions synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from twisted.internet import defer
from twisted.web import server, resource
from twisted.web.server import NOT_DONE_YET
from twisted.web.util import redirectTo

import collections
import logging
Expand Down Expand Up @@ -338,6 +339,22 @@ def stop(self, clock, request):
)


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(request, code, json_object, send_cors=False,
response_code_message=None, pretty_print=False,
version_string="", canonical_json=True):
Expand Down

0 comments on commit ba0c18e

Please sign in to comment.