45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
|
# -*- encoding: utf-8 -*-
|
||
|
|
||
|
"""
|
||
|
The application entrypoint.
|
||
|
"""
|
||
|
|
||
|
from aiohttp import web
|
||
|
import click
|
||
|
import logging
|
||
|
import os
|
||
|
import typing as T
|
||
|
|
||
|
from bot_z.async_operator import AsyncOperator
|
||
|
from api.rest import routes
|
||
|
|
||
|
|
||
|
alog = logging.getLogger("api")
|
||
|
alog.setLevel(os.environ.get("BOTZ_LOGLEVEL", logging.INFO))
|
||
|
h = logging.StreamHandler()
|
||
|
f = logging.Formatter("%(levelname)s [%(name)s] -> %(message)s")
|
||
|
h.setFormatter(f)
|
||
|
alog.addHandler(h)
|
||
|
BASE_URI = os.environ.get("BOTZ_BASE_URI")
|
||
|
|
||
|
|
||
|
def run(address: T.Text, port: int) -> None:
|
||
|
"""Application entrypoint."""
|
||
|
app = web.Application(logger=alog)
|
||
|
app["async_operator"] = AsyncOperator(BASE_URI, "test")
|
||
|
app.add_routes(routes)
|
||
|
web.run_app(app, host=address, port=port)
|
||
|
|
||
|
|
||
|
@click.command()
|
||
|
@click.option(
|
||
|
"-a",
|
||
|
"--address",
|
||
|
type=click.STRING,
|
||
|
help="Address to bind the server to.",
|
||
|
default="127.0.0.1",
|
||
|
)
|
||
|
@click.option("-p", "--port", type=click.INT, help="Port to bind to", default=3003)
|
||
|
def cli(address: T.Text, port: int) -> None:
|
||
|
run(address, port)
|