Context: using vercel and pythonanywhere to deploy. In backend, i have this endpoint:
@leaveManager.route('/postLeaveRq',methods=['POST'])
def PostLeave():
if 'employeeId' not in session or 'id' not in session:
return jsonify({"status":"error"}),401
empId = session.get("employeeId")
auth_id = session.get("id")
data = rq.get_json()
name = data.get('name')
department = data.get('department')
startdate = data.get('startDate')
enddate = data.get('endDate')
reason = data.get('reason')
dateSubmitted = data.get('dateSubmitted')
try:
start = datetime.strptime(startdate, "%Y-%m-%d").date()
end = datetime.strptime(enddate, "%Y-%m-%d").date()
if reason == "":
return jsonify({"message":"Reason not given. ","status":"reason not provided"})
if end < start:
return jsonify({"message":"Invalid structure. ","status":"datetime compare error"})
status = leavehandler.createLeaveRq(auth_id=auth_id,name=name,department=department,startdate=startdate,enddate=enddate,reason=reason,dateSubmitted=dateSubmitted,empId=empId)
notifManager.insert_notification(message=f"A leave request has been issued.",adminOnly=True)
return jsonify({"message":"Leave request sent successfully.","status":status})
except Exception as e:
print(e)
return jsonify({"error":f"{e}"})```
Whats the problem i cannot debug:
This endpoint returns successfull fetch in local machine. 200 status code.
But in production it always returns 401 regardless of if conditions.
In frontend, console.error does not print.
const response = await fetch(${API_BASE_URL}/postLeaveRq, {
method: "POST",
credentials: "include",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(leaveData),
});
const data = await response.json();
console.error(data);```
What to fix: production errors