diff options
author | Jorik Schellekens <joriks@matrix.org> | 2019-08-01 18:02:48 +0100 |
---|---|---|
committer | Jorik Schellekens <joriks@matrix.org> | 2019-08-28 15:59:53 +0100 |
commit | e5765ac4afd50e32355d844bde123019ef3b3923 (patch) | |
tree | c50092062c30d2a574c5416202dfcccc7667a6d1 | |
parent | Add basic flow control (diff) | |
download | synapse-e5765ac4afd50e32355d844bde123019ef3b3923.tar.xz |
Consolidated servers to avoid CORS.
-rwxr-xr-x | synapse_topology/__init__.py | 10 | ||||
-rw-r--r-- | synapse_topology/controller/server/__init__.py | 7 | ||||
-rw-r--r-- | synapse_topology/controller/server/error_handlers.py | 5 | ||||
-rw-r--r-- | synapse_topology/controller/server/server.py | 18 | ||||
-rw-r--r-- | synapse_topology/view/server/__init__.py | 14 |
5 files changed, 22 insertions, 32 deletions
diff --git a/synapse_topology/__init__.py b/synapse_topology/__init__.py index 70c287e210..7b6563ab03 100755 --- a/synapse_topology/__init__.py +++ b/synapse_topology/__init__.py @@ -5,7 +5,6 @@ import sys import synapse_topology.controller.server as server import synapse_topology.model as model -import synapse_topology.view.server as webui_server from twisted.internet import endpoints, reactor from twisted.web.server import Site @@ -36,18 +35,11 @@ if not path.isdir(args.config_dir): model.set_config_dir(args.config_dir) -# Backend backend_endpoint = endpoints.serverFromString( - reactor, "tcp6:port=8889:interface=localhost" + reactor, "tcp6:port=8888:interface=localhost" ) backend_endpoint.listen(Site(server.app.resource())) -# Frontend - -frontend_endpoint = endpoints.serverFromString( - reactor, "tcp6:port=8888:interface=localhost" -) -frontend_endpoint.listen(Site(webui_server.app.resource())) reactor.run() diff --git a/synapse_topology/controller/server/__init__.py b/synapse_topology/controller/server/__init__.py index 18f39c0c07..05de65ead3 100644 --- a/synapse_topology/controller/server/__init__.py +++ b/synapse_topology/controller/server/__init__.py @@ -1,4 +1,7 @@ -from . import server +from klein import Klein + +app = Klein() -app = server.app +from . import server +from . import error_handlers diff --git a/synapse_topology/controller/server/error_handlers.py b/synapse_topology/controller/server/error_handlers.py index 7356ec756c..99ddfad036 100644 --- a/synapse_topology/controller/server/error_handlers.py +++ b/synapse_topology/controller/server/error_handlers.py @@ -6,14 +6,13 @@ from synapse_topology.model.errors import ( ConfigNotFoundError, ) -from . import server - -app = server.app +from . import app @app.handle_errors(ValidationError) def validation_error(request, failure): request.setResponseCode(400) + print("Invalid post schema {}".format(failure.getErrorMessage())) return "Invalid post schema {}".format(failure.getErrorMessage()) diff --git a/synapse_topology/controller/server/server.py b/synapse_topology/controller/server/server.py index de2b3b5417..e0f0e10766 100644 --- a/synapse_topology/controller/server/server.py +++ b/synapse_topology/controller/server/server.py @@ -1,12 +1,22 @@ +from os.path import abspath, dirname, join + from canonicaljson import json -from klein import Klein from synapse_topology import model +from twisted.web.static import File + +from . import error_handlers from .schemas import BASE_CONFIG_SCHEMA, SERVERNAME_SCHEMA from .utils import validate_schema -app = Klein() -from . import error_handlers +from . import app + + +@app.route("/topology_webui/", branch=True) +def server_webui(request): + client_path = abspath(join(dirname(abspath(__file__)), "../../view/webui")) + print(client_path) + return File(client_path) @app.route("/setup", methods=["GET"]) @@ -27,7 +37,7 @@ def set_server_name(request, body): @app.route("/secretkey", methods=["GET"]) def get_secret_key(request): - return model.get_secret_key() + return json.dumps({"secret_key": model.get_secret_key()}) @app.route("/config", methods=["GET"]) diff --git a/synapse_topology/view/server/__init__.py b/synapse_topology/view/server/__init__.py deleted file mode 100644 index 5a93a18aa9..0000000000 --- a/synapse_topology/view/server/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -from os.path import abspath, dirname, join - -from klein import Klein - -from twisted.web.static import File - -app = Klein() - - -@app.route("/topology_webui/", branch=True) -def server_webui(request): - client_path = abspath(join(dirname(abspath(__file__)), "../webui")) - print(client_path) - return File(client_path) |