nova-api/api/main.py

43 lines
831 B
Python
Raw Normal View History

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
import users
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():
2023-08-01 02:38:55 +02:00
await users.prepare()
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-01 02:38:55 +02:00
app.add_route('/v1/{path:path}', transfer.handle_api_request, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])