Support additional routes
Closes https://git.autonomic.zone/decentral1se/xbotlib/issues/31.
This commit is contained in:
parent
6a30078351
commit
09e4c97597
|
@ -3,6 +3,7 @@
|
|||
# xbotlib x.x.x (UNRELEASED)
|
||||
|
||||
- Add `setup` function hook ([#36](https://git.autonomic.zone/decentral1se/xbotlib/issues/36))
|
||||
- Add support for defining additional routes ([#31](https://git.autonomic.zone/decentral1se/xbotlib/issues/31))
|
||||
|
||||
# xbotlib 0.15.1 (2021-01-24)
|
||||
|
||||
|
|
16
README.md
16
README.md
|
@ -25,6 +25,7 @@ you want to chat or just invite your bots for testing.
|
|||
- [Bot.direct(message)](#bot-direct-message)
|
||||
- [Bot.group(message)](#bot-group-message)
|
||||
- [Bot.serve(request)](#bot-serve-request)
|
||||
- [Bot.routes()](#bot-routes)
|
||||
- [Bot.setup()](#bot-setup)
|
||||
- [SimpleMessage](#simplemessage)
|
||||
- [Bot](#bot)
|
||||
|
@ -115,6 +116,21 @@ Arguments:
|
|||
|
||||
- **request**: the web request
|
||||
|
||||
### Bot.routes()
|
||||
|
||||
Register additional routes for web serving.
|
||||
|
||||
See [this section](#serving-http) for more.
|
||||
|
||||
This is an advanced feature. Use `self.web.add_routes`.
|
||||
|
||||
```python
|
||||
from aiohttp.web import get
|
||||
|
||||
def routes(self):
|
||||
self.web.add_routes([get("/foo", self.foo)])
|
||||
```
|
||||
|
||||
### Bot.setup()
|
||||
|
||||
Run some setup logic before starting your bot.
|
||||
|
|
|
@ -702,6 +702,12 @@ class Bot(ClientXMPP):
|
|||
except Exception:
|
||||
self.web.add_routes([get("/", self.default_serve)])
|
||||
|
||||
try:
|
||||
self.routes()
|
||||
self.log.info("Registered additional web routes")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self.log.info(f"Serving on http://0.0.0.0:{self.port}")
|
||||
run_app(self.web, port=self.port, print=None)
|
||||
|
||||
|
|
Loading…
Reference in New Issue