nova-api/api/main.py

44 lines
1 KiB
Python
Raw Permalink Normal View History

2023-07-19 23:51:28 +02:00
"""FastAPI setup."""
2023-06-23 02:18:28 +02:00
import fastapi
2023-08-05 02:30:42 +02:00
from rich import print
2023-06-23 02:18:28 +02:00
from dotenv import load_dotenv
2023-08-05 02:30:42 +02:00
from fastapi.middleware.cors import CORSMiddleware
2023-06-23 02:18:28 +02:00
2023-08-01 02:38:55 +02:00
import core
2023-06-28 15:21:14 +02:00
import transfer
2023-06-23 02:18:28 +02:00
load_dotenv()
app = fastapi.FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*']
)
2023-08-01 02:38:55 +02:00
app.include_router(core.router)
2023-06-23 02:18:28 +02:00
@app.on_event('startup')
async def startup_event():
# DATABASE FIX https://stackoverflow.com/questions/65970988/python-mongodb-motor-objectid-object-is-not-iterable-error-while-trying-to-f
import pydantic, bson
pydantic.json.ENCODERS_BY_TYPE[bson.objectid.ObjectId]=str
2023-06-23 02:18:28 +02:00
@app.get('/')
async def root():
"""Returns the root endpoint."""
return {
'status': 'ok',
2023-08-01 02:38:55 +02:00
'usage_docs': 'https://nova-oss.com',
'core_api_docs_for_developers': '/docs',
'github': 'https://github.com/novaoss/nova-api'
2023-06-23 02:18:28 +02:00
}
app.add_route('/{path:path}', transfer.handle, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])