fix(main): added cors headers manually

This commit is contained in:
darkicewolf50 2025-01-25 13:28:58 -07:00
parent 5835fcf508
commit 26180dc11b

33
main.py
View File

@ -15,16 +15,20 @@ if not os.path.isfile(file_name):
os.makedirs(os.path.dirname(file_name), exist_ok=True) os.makedirs(os.path.dirname(file_name), exist_ok=True)
NoSheet(file_name) NoSheet(file_name)
app = FastAPI()
# Add CORS Middleware to allow cross-origin requests app = FastAPI()
app.add_middleware( """
CORSMiddleware, YOU MUST ADD CORS MANUALLY TO ANY METHOD USE THIS TEMPLATE
allow_origins=["*"], # Allow all origins, you can replace "*" with a specific list like ["https://example.com"] ADD TO JSONRESPONSE
allow_credentials=True,
allow_methods=["*"], # Allow all HTTP methods (GET, POST, etc.) headers={
allow_headers=["*"], # Allow all headers "isBase64Encoded": "false", # Header Modification
) # Adding CORS headers explicitly
"Access-Control-Allow-Origin": "*", # Allow all origins
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", # Allowed methods
"Access-Control-Allow-Headers": "*", # Allow all headers
},
"""
@app.get("/") @app.get("/")
def get_root(): def get_root():
@ -47,6 +51,9 @@ def get_root():
return JSONResponse( return JSONResponse(
headers={ headers={
"isBase64Encoded": "false", # Header Modification "isBase64Encoded": "false", # Header Modification
"Access-Control-Allow-Origin": "*", # Allow all origins
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", # Allowed methods
"Access-Control-Allow-Headers": "*", # Allow all headers
}, },
content={ content={
"body": res # Ensure res is a dict or do json.dumps to enusre it is stringified "body": res # Ensure res is a dict or do json.dumps to enusre it is stringified
@ -78,6 +85,10 @@ async def getAppointments():
return JSONResponse( return JSONResponse(
headers={ headers={
"isBase64Encoded": "false", # Header Modification "isBase64Encoded": "false", # Header Modification
# Adding CORS headers explicitly
"Access-Control-Allow-Origin": "*", # Allow all origins
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", # Allowed methods
"Access-Control-Allow-Headers": "*", # Allow all headers
}, },
content={ content={
"body": res # Ensure res is a dict or do json.dumps to enusre it is stringified "body": res # Ensure res is a dict or do json.dumps to enusre it is stringified
@ -128,6 +139,10 @@ async def postSelectInterview(rawRequest: Appointment):
return JSONResponse( return JSONResponse(
headers={ headers={
"isBase64Encoded": "false", # Header Modification "isBase64Encoded": "false", # Header Modification
# Adding CORS headers explicitly
"Access-Control-Allow-Origin": "*", # Allow all origins
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", # Allowed methods
"Access-Control-Allow-Headers": "*", # Allow all headers
}, },
content={ content={
"body": res # Ensure res is a dict or do json.dumps to enusre it is stringified "body": res # Ensure res is a dict or do json.dumps to enusre it is stringified