mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
We don't need to be able to disable websocket
This commit is contained in:
parent
eb6d56f7ab
commit
b6258de2db
3 changed files with 22 additions and 35 deletions
|
@ -73,7 +73,7 @@ def init(logging_config=None, **kwargs):
|
|||
|
||||
# Easy access to interfaces
|
||||
def api(
|
||||
namespaces, host="localhost", port=80, routes={}, use_websocket=True, use_cache=True
|
||||
namespaces, host="localhost", port=80, routes={}, use_cache=True
|
||||
):
|
||||
"""Web server (API) interface
|
||||
|
||||
|
@ -85,7 +85,6 @@ def api(
|
|||
- port -- Server port to bind to
|
||||
- routes -- A dict of additional routes to add in the form of
|
||||
{(method, uri): callback}
|
||||
- use_websocket -- Serve via WSGI to handle asynchronous responses
|
||||
- use_cache -- False if it should parse the actions map file
|
||||
instead of using the cached one
|
||||
|
||||
|
@ -97,8 +96,7 @@ def api(
|
|||
namespaces=namespaces,
|
||||
use_cache=use_cache)
|
||||
interface = Interface(actionsmap=actionsmap,
|
||||
routes=routes,
|
||||
use_websocket=use_websocket)
|
||||
routes=routes)
|
||||
interface.run(host, port)
|
||||
except MoulinetteError as e:
|
||||
import logging
|
||||
|
|
|
@ -10,7 +10,7 @@ from gevent import sleep
|
|||
from gevent.queue import Queue
|
||||
from geventwebsocket import WebSocketError
|
||||
|
||||
from bottle import run, request, response, Bottle, HTTPResponse
|
||||
from bottle import request, response, Bottle, HTTPResponse
|
||||
from bottle import abort
|
||||
|
||||
from moulinette import msignals, m18n, env
|
||||
|
@ -219,22 +219,18 @@ class _ActionsMapPlugin(object):
|
|||
|
||||
Keyword arguments:
|
||||
- actionsmap -- An ActionsMap instance
|
||||
- use_websocket -- If true, install a WebSocket on /messages in order
|
||||
to serve messages coming from the 'display' signal
|
||||
|
||||
"""
|
||||
|
||||
name = "actionsmap"
|
||||
api = 2
|
||||
|
||||
def __init__(self, actionsmap, use_websocket, log_queues={}):
|
||||
def __init__(self, actionsmap, log_queues={}):
|
||||
# Connect signals to handlers
|
||||
msignals.set_handler("authenticate", self._do_authenticate)
|
||||
if use_websocket:
|
||||
msignals.set_handler("display", self._do_display)
|
||||
msignals.set_handler("display", self._do_display)
|
||||
|
||||
self.actionsmap = actionsmap
|
||||
self.use_websocket = use_websocket
|
||||
self.log_queues = log_queues
|
||||
# TODO: Save and load secrets?
|
||||
self.secrets = {}
|
||||
|
@ -290,13 +286,12 @@ class _ActionsMapPlugin(object):
|
|||
)
|
||||
|
||||
# Append messages route
|
||||
if self.use_websocket:
|
||||
app.route(
|
||||
"/messages",
|
||||
name="messages",
|
||||
callback=self.messages,
|
||||
skip=["actionsmap"],
|
||||
)
|
||||
app.route(
|
||||
"/messages",
|
||||
name="messages",
|
||||
callback=self.messages,
|
||||
skip=["actionsmap"],
|
||||
)
|
||||
|
||||
# Append routes from the actions map
|
||||
for (m, p) in self.actionsmap.parser.routes:
|
||||
|
@ -737,14 +732,12 @@ class Interface(BaseInterface):
|
|||
- actionsmap -- The ActionsMap instance to connect to
|
||||
- routes -- A dict of additional routes to add in the form of
|
||||
{(method, path): callback}
|
||||
- use_websocket -- Serve via WSGI to handle asynchronous responses
|
||||
- log_queues -- A LogQueues object or None to retrieve it from
|
||||
registered logging handlers
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, actionsmap, routes={}, use_websocket=True, log_queues=None):
|
||||
self.use_websocket = use_websocket
|
||||
def __init__(self, actionsmap, routes={}, log_queues=None):
|
||||
|
||||
# Attempt to retrieve log queues from an APIQueueHandler
|
||||
if log_queues is None:
|
||||
|
@ -776,7 +769,7 @@ class Interface(BaseInterface):
|
|||
app.install(filter_csrf)
|
||||
app.install(apiheader)
|
||||
app.install(api18n)
|
||||
app.install(_ActionsMapPlugin(actionsmap, use_websocket, log_queues))
|
||||
app.install(_ActionsMapPlugin(actionsmap, log_queues))
|
||||
|
||||
# Append default routes
|
||||
# app.route(['/api', '/api/<category:re:[a-z]+>'], method='GET',
|
||||
|
@ -801,23 +794,19 @@ class Interface(BaseInterface):
|
|||
|
||||
"""
|
||||
logger.debug(
|
||||
"starting the server instance in %s:%d with websocket=%s",
|
||||
"starting the server instance in %s:%d",
|
||||
host,
|
||||
port,
|
||||
self.use_websocket,
|
||||
)
|
||||
|
||||
try:
|
||||
if self.use_websocket:
|
||||
from gevent.pywsgi import WSGIServer
|
||||
from geventwebsocket.handler import WebSocketHandler
|
||||
from gevent.pywsgi import WSGIServer
|
||||
from geventwebsocket.handler import WebSocketHandler
|
||||
|
||||
server = WSGIServer(
|
||||
(host, port), self._app, handler_class=WebSocketHandler
|
||||
)
|
||||
server.serve_forever()
|
||||
else:
|
||||
run(self._app, host=host, port=port)
|
||||
server = WSGIServer(
|
||||
(host, port), self._app, handler_class=WebSocketHandler
|
||||
)
|
||||
server.serve_forever()
|
||||
except IOError as e:
|
||||
logger.exception("unable to start the server instance on %s:%d", host, port)
|
||||
if e.args[0] == errno.EADDRINUSE:
|
||||
|
|
|
@ -125,7 +125,7 @@ def moulinette_webapi(moulinette):
|
|||
|
||||
CookiePolicy.return_ok_secure = return_true
|
||||
|
||||
moulinette_webapi = moulinette.core.init_interface(
|
||||
moulinette_webapi = moulinette.init_interface(
|
||||
"api",
|
||||
kwargs={"routes": {}, "use_websocket": False},
|
||||
actionsmap={"namespaces": ["moulitest"], "use_cache": True},
|
||||
|
@ -148,7 +148,7 @@ def moulinette_cli(moulinette, mocker):
|
|||
help="Log and print debug messages",
|
||||
)
|
||||
mocker.patch("os.isatty", return_value=True)
|
||||
moulinette_cli = moulinette.core.init_interface(
|
||||
moulinette_cli = moulinette.init_interface(
|
||||
"cli",
|
||||
actionsmap={
|
||||
"namespaces": ["moulitest"],
|
||||
|
|
Loading…
Add table
Reference in a new issue