Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
9fd445eb
Commit
9fd445eb
authored
10 years ago
by
Kegan Dougal
Browse files
Options
Downloads
Patches
Plain Diff
If the web client is enabled, automatically redirect root '/' to the web client path.
parent
e543d6a9
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/app/homeserver.py
+13
-4
13 additions, 4 deletions
synapse/app/homeserver.py
synapse/http/server.py
+17
-0
17 additions, 0 deletions
synapse/http/server.py
with
30 additions
and
4 deletions
synapse/app/homeserver.py
+
13
−
4
View file @
9fd445eb
...
...
@@ -24,7 +24,7 @@ from twisted.python.log import PythonLoggingObserver
from
twisted.web.resource
import
Resource
from
twisted.web.static
import
File
from
twisted.web.server
import
Site
from
synapse.http.server
import
JsonResource
from
synapse.http.server
import
JsonResource
,
RootRedirect
from
synapse.http.client
import
TwistedHttpClient
from
synapse.rest.base
import
CLIENT_PREFIX
from
synapse.federation.transport
import
PREFIX
...
...
@@ -85,7 +85,7 @@ class SynapseHomeServer(HomeServer):
return
pool
def
create_resource_tree
(
self
,
web_client
):
def
create_resource_tree
(
self
,
web_client
,
redirect_root_to_
web_client
):
"""
Create the resource tree for this Home Server.
This in unduly complicated because Twisted does not support putting
...
...
@@ -93,6 +93,9 @@ class SynapseHomeServer(HomeServer):
Args:
web_client (bool): True to enable the web client.
redirect_root_to_web_client (bool): True to redirect
'
/
'
to the
location of the web client. This does nothing if web_client is not
True.
"""
# list containing (path_str, Resource) e.g:
# [ ("/aaa/bbb/cc", Resource1), ("/aaa/dummy", Resource2) ]
...
...
@@ -105,7 +108,11 @@ class SynapseHomeServer(HomeServer):
desired_tree
.
append
((
"
/matrix/client
"
,
# TODO constant please
self
.
get_resource_for_web_client
()))
self
.
root_resource
=
Resource
()
if
web_client
and
redirect_root_to_web_client
:
self
.
root_resource
=
RootRedirect
(
"
/matrix/client
"
)
else
:
self
.
root_resource
=
Resource
()
# ideally we'd just use getChild and putChild but getChild doesn't work
# unless you give it a Request object IN ADDITION to the name :/ So
# instead, we'll store a copy of this mapping so we can actually add
...
...
@@ -247,7 +254,9 @@ def setup():
hs
.
register_servlets
()
hs
.
create_resource_tree
(
web_client
=
args
.
webclient
)
hs
.
create_resource_tree
(
web_client
=
args
.
webclient
,
redirect_root_to_web_client
=
True
)
hs
.
start_listening
(
args
.
port
)
hs
.
build_db_pool
()
...
...
This diff is collapsed.
Click to expand it.
synapse/http/server.py
+
17
−
0
View file @
9fd445eb
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment