Mercurial > libervia-web
view libervia/pages/_browser/aio_bridge.py @ 1360:389a83eefe62
server: SàT applications integration:
- a SàT Application can be added to the menu (if necessary values are exposed), by using
the `sat-app:[application_name]` in `menu_json` or `menu_extra_json`. The application
will then be started with Libervia, and embedded, i.e. Libervia menu will appear and
application will be integrated under it.
- the same `sat-app:[application_name]` thing can be used in redirection, in this case the
redirection will reverse proxy directly the application, without embedding it (no
Libervia menu will appear)
- the ReverseProxy will replace headers if necessary to allow embedding in a iframe from
the same domain
- new `embed_app` page to embed a SàT Application
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 28 Sep 2020 21:12:21 +0200 |
parents | 48e2a8b07c0b |
children | 72f9639594b2 |
line wrap: on
line source
from browser import window, aio import javascript class BridgeException(Exception): """An exception which has been raised from the backend and arrived to the frontend.""" def __init__(self, name, message="", condition=""): """ @param name (str): full exception class name (with module) @param message (str): error message @param condition (str) : error condition """ Exception.__init__(self) self.fullname = str(name) self.message = str(message) self.condition = str(condition) if condition else "" self.module, __, self.classname = str(self.fullname).rpartition(".") def __str__(self): message = (": %s" % self.message) if self.message else "" return self.classname + message def __eq__(self, other): return self.classname == other class Bridge: def __getattr__(self, attr): return lambda *args, **kwargs: self.call(attr, *args, **kwargs) async def call(self, method_name, *args, **kwargs): data = javascript.JSON.stringify({ "args": args, "kwargs": kwargs, }) url = f"/_bridge/{method_name}" r = await aio.post( url, headers={ 'X-Csrf-Token': window.csrf_token, }, data=data, ) if r.status == 200: return javascript.JSON.parse(r.data) elif r.status == 502: ret = javascript.JSON.parse(r.data) raise BridgeException(ret['fullname'], ret['message'], ret['condition']) else: print(f"bridge called failed: code: {r.status}, text: {r.statusText}") raise BridgeException("InternalError", r.statusText)