from uvicorn import Config, Server
from starlette.applications import Starlette
from starlette.routing import Route
from serverside.helpers.config import get
from serverside.helpers.middleware import RateLimitMiddleware
from serverside.routes.version import version

async def start_server():
    app = Starlette(debug=get("general", "debug", fallback=False), 
        routes=[
            Route("/version", version),
            Route("/api/version", version),
            Route("/api/v1/version", version),
            Route("/get_version", version)
        ]
    )
    app.add_middleware(RateLimitMiddleware)

    
    config = Config(
        app=app,
        host=get("network", "host", fallback="127.0.0.1"),
        port=int(get("network", "port", fallback=56000)),
        log_level="debug" if get("general", "debug", fallback=False) else "info",
    )

    server = Server(config)
    await server.serve()