Files
FileStreamBot-Caduceus/bot/server/__init__.py
Dr.Caduceus d438b97d39 Bump to v1.1
2023-11-07 14:34:12 +05:30

30 lines
921 B
Python

from quart import Quart
from hypercorn import Config
from hypercorn.asyncio import serve
from logging import getLogger
from bot.config import Server, LOGGER_CONFIG_JSON
from . import main, error
logger = getLogger('hypercorn')
instance = Quart(__name__)
@instance.before_serving
async def before_serve():
logger.info('Web server is started!')
logger.info(f'Server running on {Server.BIND_ADDRESS}:{Server.PORT}')
instance.register_blueprint(main.bp)
instance.register_error_handler(400, error.invalid_request)
instance.register_error_handler(404, error.not_found)
instance.register_error_handler(405, error.invalid_method)
instance.register_error_handler(error.HTTPError, error.http_error)
async def run_server():
config = Config()
config.bind = [f'{Server.BIND_ADDRESS}:{Server.PORT}']
config.logconfig_dict = LOGGER_CONFIG_JSON
await serve(instance, config)