nova-api/api/main.py

43 lines
894 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
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-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():
"""Runs when the API starts up."""
2023-06-23 02:18:28 +02:00
@app.get('/')
async def root():
2023-08-13 17:12:35 +02:00
"""
Returns general information about the API.
2023-08-13 17:12:35 +02:00
"""
2023-06-23 02:18:28 +02:00
return {
'hi': 'Welcome to the Nova API!',
'learn_more_here': 'https://nova-oss.com',
'github': 'https://github.com/novaoss/nova-api',
'core_api_docs_for_nova_developers': '/docs'
2023-06-23 02:18:28 +02:00
}
2023-08-22 20:03:55 +02:00
app.add_route('/v1/{path:path}', transfer.handle, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])