2023-06-23 02:18:28 +02:00
|
|
|
import os
|
|
|
|
import fastapi
|
|
|
|
|
|
|
|
from starlette.responses import StreamingResponse
|
2023-06-28 15:21:14 +02:00
|
|
|
from starlette.requests import Request
|
2023-06-23 02:18:28 +02:00
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
import security
|
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."""
|
|
|
|
|
|
|
|
security.enable_proxy()
|
|
|
|
security.ip_protection_check()
|
|
|
|
|
|
|
|
@app.get('/')
|
|
|
|
async def root():
|
|
|
|
"""Returns the root endpoint."""
|
|
|
|
|
|
|
|
return {
|
|
|
|
'status': 'ok',
|
2023-06-24 20:56:56 +02:00
|
|
|
'discord': 'https://discord.gg/85gdcd57Xr',
|
2023-06-23 02:18:28 +02:00
|
|
|
'github': 'https://github.com/Luna-OSS'
|
|
|
|
}
|
|
|
|
|
|
|
|
async def _reverse_proxy(request: Request):
|
2023-06-28 15:21:14 +02:00
|
|
|
headers = {
|
|
|
|
name: value
|
|
|
|
for name, value in target_response.headers.items()
|
|
|
|
if name.lower() not in EXCLUDED_HEADERS
|
|
|
|
}
|
2023-06-23 02:18:28 +02:00
|
|
|
|
2023-06-28 15:21:14 +02:00
|
|
|
# ...
|
2023-06-23 02:18:28 +02:00
|
|
|
|
|
|
|
app.add_route('/{path:path}', _reverse_proxy, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
|