2023-07-19 23:51:28 +02:00
|
|
|
"""FastAPI setup."""
|
|
|
|
|
2023-06-23 02:18:28 +02:00
|
|
|
import fastapi
|
|
|
|
|
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
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
|
|
|
|
2023-08-03 01:46:49 +02:00
|
|
|
from db import users
|
|
|
|
|
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():
|
2023-08-03 01:46:49 +02:00
|
|
|
# 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
|
|
|
}
|
|
|
|
|
2023-08-03 01:46:49 +02:00
|
|
|
app.add_route('/{path:path}', transfer.handle, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
|