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)
|
# xbotlib x.x.x (UNRELEASED)
|
||||||
|
|
||||||
- Add `setup` function hook ([#36](https://git.autonomic.zone/decentral1se/xbotlib/issues/36))
|
- 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)
|
# 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.direct(message)](#bot-direct-message)
|
||||||
- [Bot.group(message)](#bot-group-message)
|
- [Bot.group(message)](#bot-group-message)
|
||||||
- [Bot.serve(request)](#bot-serve-request)
|
- [Bot.serve(request)](#bot-serve-request)
|
||||||
|
- [Bot.routes()](#bot-routes)
|
||||||
- [Bot.setup()](#bot-setup)
|
- [Bot.setup()](#bot-setup)
|
||||||
- [SimpleMessage](#simplemessage)
|
- [SimpleMessage](#simplemessage)
|
||||||
- [Bot](#bot)
|
- [Bot](#bot)
|
||||||
@ -115,6 +116,21 @@ Arguments:
|
|||||||
|
|
||||||
- **request**: the web request
|
- **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()
|
### Bot.setup()
|
||||||
|
|
||||||
Run some setup logic before starting your bot.
|
Run some setup logic before starting your bot.
|
||||||
|
@ -702,6 +702,12 @@ class Bot(ClientXMPP):
|
|||||||
except Exception:
|
except Exception:
|
||||||
self.web.add_routes([get("/", self.default_serve)])
|
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}")
|
self.log.info(f"Serving on http://0.0.0.0:{self.port}")
|
||||||
run_app(self.web, port=self.port, print=None)
|
run_app(self.web, port=self.port, print=None)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user