Open ccrighton opened 1 year ago
I've created a pull request: Refactor Phew as a class to support multiple apps on one device running singly or concurrently #53
Currently, the run method takes control of the asyncio loop. That means nothing else can be added as a task. As a result, it's not possible to run anything but a web app. I've introduced a run_as_task method that doesn't ceed control of the loop. That means that Phew can be run alongside other functions such as an mqtt client, interrupt handlers and so on.
Hi,
I have an application that has two web apps. One for the initial AP configuration of the device and the second for the ongoing maintenance. Unfortunately, with phew the decorators store the routes in a global.
Phew could support this capability if the routes were stored as instance variables of a Phew server class. You'll see the similarity to Flask. The following tweak of the basic example demonstrates the idea:
It would still be possible to not break existing apps by using a default instance of Phew in the case that the existing methods are called. In the implementation the server.route method etc. would apply to a default Phew instance stored in a server.py global variable.