-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapi.py
More file actions
58 lines (41 loc) · 1.63 KB
/
api.py
File metadata and controls
58 lines (41 loc) · 1.63 KB
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
54
55
56
57
58
#!/usr/bin/python
"""
cryptomon-api.py A FastAPI based interface for a MongoDB database,
that is ingesting processed TLS data from a cryptomon service.
Licensed under the Apache License, Version 2.0 (the "License")
Author: Mark Carney (mark[.]carney[@]gruposantander[.]com)
"""
__author__ = "Mark Carney"
__copyright__ = "Copyright 2024, Mark Carney"
__credits__ = ["Mark Carney"]
__license__ = "GLP 3.0"
__version__ = "1.0.0"
__maintainer__ = "Mark Carney"
__email__ = "mark.carney@gruposantander.com"
__status__ = "Demonstration"
from fastapi import FastAPI
# from fastapi.middleware.cors import CORSMiddleware
# from starlette.responses import FileResponse
# from starlette.staticfiles import StaticFiles
import uvicorn
from motor.motor_asyncio import AsyncIOMotorClient
from fapi.config import settings
from fapi.app.routers import router as data_routers
app = FastAPI()
@app.on_event("startup")
async def startup_dbclient_and_monitor():
app.mongodb_client = AsyncIOMotorClient(settings.DB_URL)
app.mongodb = app.mongodb_client[settings.DB_NAME]
@app.on_event("shutdown")
async def shutdown_db_client():
app.mongodb_client.close()
# Add CORS middleware if needed...
# app.add_middleware(CORSMiddleware,allow_origins="*",allow_credentials=True,allow_methods=["*"],allow_headers=["*"],)
app.include_router(data_routers, tags=["cryptomon"], prefix="/data")
# load some static pages, if required.
# app.mount("/", StaticFiles(directory="frontend/dist/"), name="ui")
if __name__ == "__main__":
uvicorn.run("api:app",
host=settings.HOST,
reload=settings.DEBUG_MODE,
port=settings.PORT,)