2022-03-15 16:19:37 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import uvicorn
|
2022-03-16 14:54:42 +00:00
|
|
|
from fastapi import Depends, FastAPI
|
|
|
|
from peewee import Database
|
2022-03-15 17:38:24 +00:00
|
|
|
|
2022-03-15 16:25:07 +00:00
|
|
|
from .config import PRODUCTION_MODE
|
2022-03-16 14:54:42 +00:00
|
|
|
from .db import DB
|
|
|
|
from .routers import auth, install, user
|
2022-03-15 16:19:37 +00:00
|
|
|
|
|
|
|
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,
|
2022-03-15 22:42:29 +00:00
|
|
|
redoc_url="/redoc" if not PRODUCTION_MODE else None,
|
2022-03-15 16:19:37 +00:00
|
|
|
)
|
|
|
|
|
2022-03-15 17:38:24 +00:00
|
|
|
api.include_router(install.router)
|
2022-03-15 16:19:37 +00:00
|
|
|
api.include_router(auth.router)
|
|
|
|
api.include_router(user.router)
|
2022-03-14 00:10:10 +00:00
|
|
|
|
2022-03-16 14:54:42 +00:00
|
|
|
|
|
|
|
@api.on_event("startup")
|
|
|
|
async def api_startup(
|
|
|
|
db: Database = Depends(install.connect_db)
|
|
|
|
):
|
|
|
|
DB.initialize(db)
|
|
|
|
|
2022-03-14 00:10:10 +00:00
|
|
|
app = FastAPI()
|
2022-03-15 16:19:37 +00:00
|
|
|
app.mount("/api", api)
|
|
|
|
|
2022-03-14 00:10:10 +00:00
|
|
|
|
2022-03-15 16:19:37 +00:00
|
|
|
def main():
|
|
|
|
uvicorn.run(
|
|
|
|
"kiwi_vpn_api.main:app",
|
|
|
|
host="0.0.0.0",
|
|
|
|
port=8000,
|
|
|
|
reload=True,
|
|
|
|
)
|
2022-03-14 00:10:10 +00:00
|
|
|
|
|
|
|
|
2022-03-15 16:19:37 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|