-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
53 lines (43 loc) · 1.45 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import uvicorn
from fastapi import FastAPI
from fastapi.responses import RedirectResponse, JSONResponse
import requests
import os
from dotenv import load_dotenv
from utils.logger import logger
from routes import routes121, routesEspo, routesGeneric, routesKobo
# load environment variables
load_dotenv()
port = os.environ["PORT"]
# initialize FastAPI
app = FastAPI(
title="kobo-connect",
description="Connect Kobo to anything, including itself. \n"
"Built with love by [NLRC 510](https://www.510.global/). "
"See [the project on GitHub](https://github.com/rodekruis/kobo-connect) "
"or [contact us](mailto:[email protected]).",
version="0.0.3",
license_info={
"name": "AGPL-3.0 license",
"url": "https://www.gnu.org/licenses/agpl-3.0.en.html",
},
)
@app.get("/", include_in_schema=False)
async def docs_redirect():
"""Redirect base URL to docs."""
return RedirectResponse(url="/docs")
# Include routes
app.include_router(routes121.router)
app.include_router(routesEspo.router)
app.include_router(routesGeneric.router)
app.include_router(routesKobo.router)
@app.get("/health")
async def health():
"""Get health of instance."""
kobo = requests.get(f"https://kobo.ifrc.org/api/v2")
return JSONResponse(
status_code=200,
content={"kobo-connect": 200, "kobo.ifrc.org": kobo.status_code},
)
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=int(port), reload=True)