From c3acb3ca45480d3a4d72731ca68b69bec6db4e2c Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Wed, 9 Nov 2016 15:42:04 +0100 Subject: [refactor] remove duplication of the bitmask.js library --- src/leap/bitmask/core/_web.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/leap/bitmask/core/_web.py') diff --git a/src/leap/bitmask/core/_web.py b/src/leap/bitmask/core/_web.py index 715356d..1cbba19 100644 --- a/src/leap/bitmask/core/_web.py +++ b/src/leap/bitmask/core/_web.py @@ -32,6 +32,7 @@ from twisted.web.server import Site, NOT_DONE_YET from twisted.web.static import File from twisted.logger import Logger +from leap.bitmask.util import here from leap.bitmask.core.dispatcher import CommandDispatcher try: @@ -52,8 +53,14 @@ class HTTPDispatcherService(service.Service): """ A Dispatcher for BitmaskCore exposing a REST API. - If the leap.bitmask_js package is available in the search path, it will - serve the UI under this same service too. + + The API itself is served under the API/ route. + + If the package ``leap.bitmask_js`` is found in the import path, we'll serve + the whole JS UI in the root resource too (under the ``public`` path). + + If that package cannot be found, we'll serve just the javascript wrapper + around the REST API. """ def __init__(self, core, port=7070, debug=False, onion=False): @@ -72,14 +79,22 @@ class HTTPDispatcherService(service.Service): log.warn('bitmask_js not found, serving bitmask.core ui') webdir = os.path.abspath( pkg_resources.resource_filename('leap.bitmask.core', 'web')) + jspath = os.path.join( + here(), '..', '..', '..', + 'ui', 'app', 'lib', 'bitmask.js') + jsapi = File(os.path.abspath(jspath)) root = File(webdir) api = Api(CommandDispatcher(self._core)) root.putChild(u'API', api) + # TODO --- pass requestFactory for header authentication factory = Site(root) self.site = factory + if not HAS_WEB_UI: + root.putChild('bitmask.js', jsapi) + if self.onion: try: import txtorcon -- cgit v1.2.3