8 Commits

3 changed files with 38 additions and 3 deletions

View File

@ -5,7 +5,7 @@ The Docker Project that runs on the Baja Nas
# BAJA CLoud Backend
Can be found [here](http://darkicewofl50.asuscomm.com:43443/)
Can be found [here](https://bajabackend.bajacloud.duckdns.org/)
Reason in "Baja Data 2024 - 2025/W - Software/Brock's Learning.docx"

38
main.py
View File

@ -1,5 +1,6 @@
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from InterviewBooking.NoSheet import NoSheet
@ -14,8 +15,32 @@ if not os.path.isfile(file_name):
os.makedirs(os.path.dirname(file_name), exist_ok=True)
NoSheet(file_name)
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # This allows all origins
allow_credentials=True,
allow_methods=["*"], # Allow all methods (GET, POST, OPTIONS, etc.)
allow_headers=["*"], # Allow all headers
)
"""
YOU MUST ADD CORS MANUALLY TO ANY METHOD USE THIS TEMPLATE
ADD TO JSONRESPONSE
USE APPROPRIATE METHOD fOR THE TYPE IE
@app.get = ... "Access-Control-Allow-Methods": "GET", ...
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("/")
def get_root():
"""
@ -37,6 +62,9 @@ def get_root():
return JSONResponse(
headers={
"isBase64Encoded": "false", # Header Modification
"Access-Control-Allow-Origin": "*", # Allow all origins
"Access-Control-Allow-Methods": "GET", # Allowed methods
"Access-Control-Allow-Headers": "*", # Allow all headers
},
content={
"body": res # Ensure res is a dict or do json.dumps to enusre it is stringified
@ -68,6 +96,10 @@ async def getAppointments():
return JSONResponse(
headers={
"isBase64Encoded": "false", # Header Modification
# Adding CORS headers explicitly
"Access-Control-Allow-Origin": "*", # Allow all origins
"Access-Control-Allow-Methods": "GET", # Allowed methods
"Access-Control-Allow-Headers": "*", # Allow all headers
},
content={
"body": res # Ensure res is a dict or do json.dumps to enusre it is stringified
@ -92,8 +124,8 @@ class Appointment(BaseModel):
"""
intervieweeName: str
date: str
startTime: str
date: str
intervieweeEmail: str
@ -118,6 +150,10 @@ async def postSelectInterview(rawRequest: Appointment):
return JSONResponse(
headers={
"isBase64Encoded": "false", # Header Modification
# Adding CORS headers explicitly
"Access-Control-Allow-Origin": "*", # Allow all origins
"Access-Control-Allow-Methods": "POST", # Allowed methods
"Access-Control-Allow-Headers": "*", # Allow all headers
},
content={
"body": res # Ensure res is a dict or do json.dumps to enusre it is stringified

View File

@ -1 +0,0 @@
this is only to test a discord webhook, this will be deleted later