I have tried setting up the CORS headers as per the official docs.
But when I test the endpoint locally, the CORS headers don't appear.
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import requests
from fastapi import Response
import os
load_dotenv()
key = os.environ["DRF_API_KEY"]
app = FastAPI()
origins = [
"http://localhost.tiangolo.com",
"https://localhost.tiangolo.com",
"http://localhost:8000",
"http://localhost:8080",
"http://localhost:8080",
"http://127.0.0.1:8000"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
@app.get("/{email}")
async def root(email):
print("hiya")
# print("Email is ", email)
# print("Key is ", key)
r = requests.get(f'https://api.mydomain.io/retrieve_artist_user/{email}', headers={'Authorization': f'Api-Key {key}'})
text = r.text
print(text)
return Response(content=text, media_type="application/json")
I am testing with Postman and keeping an eye on the Headers tab