top_questions / main.py
Siddhant
initial commit
bd8cd5c unverified
raw
history blame
1.12 kB
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))