mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2026-09-24 14:20:08 +01:00
* use camoufox * build custom branches * organize compose * ignore missing stubs * add init method * create ADDON PATH * check if solving is required * type checking and remove logger * uv sync * add timeout * add descriptiuon * cancel previous runs * wildcard minor * fix proxy * syntax fix * [skip ci] fix loop warning * fix proxy format * copy over docker ignore * remove testing line * comment out port expose * remove idope * use strict typechecking * refactor * adjust compose * run init only before test * try test without init * add curl * handle page response * remove turnsile test * fix dockerignore symlink * use newer debian * bump pytest * add docker in docker in devcontaienr * remove unused values * handle timeouts * fix edgecase * use new envs for proxy * remove init command * remove testing line * remove setuptools * fix linters * reimport * readd setuptools * better float handling
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.gzip import GZipMiddleware
|
|
|
|
from src.consts import LOG_LEVEL, VERSION
|
|
from src.endpoints import health_check, router
|
|
from src.middlewares import LogRequest
|
|
from src.utils import get_camoufox, logger
|
|
|
|
logger.info("Using version %s", VERSION)
|
|
|
|
app = FastAPI(debug=LOG_LEVEL == logging.DEBUG, log_level=LOG_LEVEL)
|
|
app.add_middleware(GZipMiddleware)
|
|
app.add_middleware(LogRequest)
|
|
|
|
app.include_router(router=router)
|
|
|
|
|
|
async def init():
|
|
"""Initialize the application."""
|
|
async for browser in get_camoufox():
|
|
await health_check(browser)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Check for --init flag to run the app in development mode
|
|
if "--init" in sys.argv:
|
|
logger.info("Running initialization script...")
|
|
loop = asyncio.new_event_loop()
|
|
asyncio.set_event_loop(loop)
|
|
loop.run_until_complete(init())
|
|
logger.info("Initialization complete.")
|
|
else:
|
|
host = os.getenv("HOST", "0.0.0.0") # noqa: S104
|
|
uvicorn.run(app, host=host, port=8191)
|