kiwi-vpn/api/kiwi_vpn_api/main.py
2022-03-18 17:36:44 +00:00

50 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
import uvicorn
from fastapi import Depends, FastAPI
from .config import (PRODUCTION_MODE, BaseConfig, has_config,
load_config)
from .routers import install
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",
},
docs_url="/docs" if not PRODUCTION_MODE else None,
redoc_url="/redoc" if not PRODUCTION_MODE else None,
)
api.include_router(install.router)
# api.include_router(auth.router)
# api.include_router(user.router)
app = FastAPI()
app.mount("/api", api)
@app.on_event("startup")
async def on_startup():
if await has_config():
config = await load_config()
await config.connect_db()
def main():
uvicorn.run(
"kiwi_vpn_api.main:app",
host="0.0.0.0",
port=8000,
reload=True,
)
if __name__ == "__main__":
main()