garvitcpp commited on
Commit
99156a4
·
verified ·
1 Parent(s): a97472b

Update app/api/routes.py

Browse files
Files changed (1) hide show
  1. app/api/routes.py +10 -3
app/api/routes.py CHANGED
@@ -9,9 +9,16 @@ api_bp = Blueprint('api', __name__, url_prefix='/api')
9
 
10
  @api_bp.route('/form-data', methods=['GET'])
11
  def get_form_data():
12
- with open('form_data.json', 'r') as file:
13
- data = json.load(file)
14
- return jsonify(data)
 
 
 
 
 
 
 
15
 
16
  @api_bp.route('/recommend', methods=['POST'])
17
  async def recommend_recipes(): # Make this function async
 
9
 
10
  @api_bp.route('/form-data', methods=['GET'])
11
  def get_form_data():
12
+ # Use os.path.join to create a platform-independent path
13
+ file_path = os.path.join(os.getcwd(), 'form_data.json')
14
+ try:
15
+ with open(file_path, 'r') as file:
16
+ data = file.read()
17
+ return data
18
+ except FileNotFoundError:
19
+ return jsonify({"error": f"File not found at {file_path}"}), 404
20
+ except Exception as e:
21
+ return jsonify({"error": str(e)}), 500
22
 
23
  @api_bp.route('/recommend', methods=['POST'])
24
  async def recommend_recipes(): # Make this function async