2023-07-19 23:51:28 +02:00
|
|
|
"""FastAPI setup."""
|
|
|
|
|
2023-06-23 02:18:28 +02:00
|
|
|
import fastapi
|
2023-07-19 23:51:28 +02:00
|
|
|
import asyncio
|
2023-06-23 02:18:28 +02:00
|
|
|
|
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
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=['*']
|
|
|
|
)
|
|
|
|
|
|
|
|
@app.on_event('startup')
|
|
|
|
async def startup_event():
|
|
|
|
"""Read up the API server."""
|
|
|
|
|
|
|
|
@app.get('/')
|
|
|
|
async def root():
|
|
|
|
"""Returns the root endpoint."""
|
|
|
|
|
|
|
|
return {
|
|
|
|
'status': 'ok',
|
2023-07-19 23:51:28 +02:00
|
|
|
'readme': 'https://nova-oss.com'
|
|
|
|
}
|
|
|
|
|
|
|
|
@app.route('/v1')
|
|
|
|
async def api_root():
|
|
|
|
"""Returns the API root endpoint."""
|
|
|
|
|
|
|
|
return {
|
|
|
|
'status': 'ok',
|
2023-06-23 02:18:28 +02:00
|
|
|
}
|
|
|
|
|
2023-07-25 02:42:53 +02:00
|
|
|
app.add_route('/{path:path}', transfer.handle_api_request, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
|