|
|
@@ -376,22 +376,26 @@ class WebServer: |
|
|
|
self._app.add_routes([aiohttp.web.post('/{path:.+}', self.post)]) |
|
|
|
|
|
|
|
self.update_config(config) |
|
|
|
self._configChanged = asyncio.Event() |
|
|
|
|
|
|
|
def update_config(self, config): |
|
|
|
self._paths = {map_['webpath']: (map_['ircchannel'], f'Basic {base64.b64encode(map_["auth"].encode("utf-8")).decode("utf-8")}' if map_['auth'] else False) for map_ in config['maps'].values()} |
|
|
|
needRebind = self.config['web'] != config['web'] |
|
|
|
self.config = config |
|
|
|
if needRebind: |
|
|
|
#TODO |
|
|
|
logging.error('Webserver host or port changes while running are currently not supported') |
|
|
|
self._configChanged.set() |
|
|
|
|
|
|
|
async def run(self, stopEvent): |
|
|
|
runner = aiohttp.web.AppRunner(self._app) |
|
|
|
await runner.setup() |
|
|
|
site = aiohttp.web.TCPSite(runner, self.config['web']['host'], self.config['web']['port']) |
|
|
|
await site.start() |
|
|
|
await stopEvent.wait() |
|
|
|
await runner.cleanup() |
|
|
|
while True: |
|
|
|
runner = aiohttp.web.AppRunner(self._app) |
|
|
|
await runner.setup() |
|
|
|
site = aiohttp.web.TCPSite(runner, self.config['web']['host'], self.config['web']['port']) |
|
|
|
await site.start() |
|
|
|
await asyncio.wait((stopEvent.wait(), self._configChanged.wait()), return_when = concurrent.futures.FIRST_COMPLETED) |
|
|
|
await runner.cleanup() |
|
|
|
if stopEvent.is_set(): |
|
|
|
break |
|
|
|
self._configChanged.clear() |
|
|
|
|
|
|
|
async def post(self, request): |
|
|
|
logging.info(f'Received request for {request.path!r}') |
|
|
|