kiwi-vpn/api/kiwi_vpn_api/main.py

61 lines
1.4 KiB
Python
Executable file

#!/usr/bin/env python3
import uvicorn
from fastapi import FastAPI
from .config import Config, Settings
from .db.connection import Connection
from .routers import admin, user
settings = Settings.get()
api = FastAPI(
title="kiwi-vpn API",
description="This API enables the `kiwi-vpn` service.",
contact={
"name": "Jörn-Michael Miehe",
"email": "40151420+ldericher@users.noreply.github.com",
},
license_info={
"name": "MIT License",
"url": "https://opensource.org/licenses/mit-license.php",
},
openapi_url=settings.openapi_url,
docs_url=settings.docs_url if not settings.production_mode else None,
redoc_url=settings.redoc_url if not settings.production_mode else None,
)
app = FastAPI()
app.mount("/api", api)
@app.on_event("startup")
async def on_startup():
# always include admin router
api.include_router(admin.router)
if (current_config := await Config.get()) is not None:
Connection.connect(current_config.db_engine)
# async for db in connection.get():
# user = crud.get_user(db, "admin")
# print(user.name)
# for cap in user.capabilities:
# print(cap.capability)
# include other routers
api.include_router(user.router)
def main():
uvicorn.run(
"kiwi_vpn_api.main:app",
host="0.0.0.0",
port=8000,
reload=True,
)
if __name__ == "__main__":
main()