Spaces:
Runtime error
Runtime error
File size: 1,123 Bytes
bd8cd5c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from fastapi import FastAPI, HTTPException, Header, status, Body, Request
from typing import Annotated
import os
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv
from utils.GetTopAndRecentQuestions import return_top_question
load_dotenv()
app = FastAPI(docs_url="/documentation", redoc_url=None)
origins = [
"http://localhost:4200",
"https://releasepreview.twimbit.com"
]
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
token = os.getenv("token")
@app.get("/get_top_questions", status_code=status.HTTP_200_OK)
def get_top_questions_(limit: int = 5, Authorization: Annotated[list[str] | None, Header()] = None):
if Authorization is None or Authorization[0] != "Bearer {}".format(token):
raise HTTPException(status_code=401, detail="Unauthorised.")
try:
# return {'data': return_top_question(limit)}
return {'data': 'success'}
except Exception as e:
# return a success message
raise HTTPException(status_code=400, detail=str(e))
|