saman shrestha commited on
Commit
eb31690
·
1 Parent(s): 409ca5a

cors fixed

Browse files
Files changed (1) hide show
  1. flask_app.py +10 -1
flask_app.py CHANGED
@@ -1,4 +1,5 @@
1
  from flask import Flask, g, render_template, request, jsonify, session
 
2
  import os
3
 
4
  from helpers.GROQ import ConversationGROQ
@@ -8,6 +9,7 @@ import re
8
  import pandas as pd
9
 
10
  app = Flask(__name__)
 
11
  app.secret_key = os.urandom(24) # Set a secret key for session encryption
12
  app.config["SESSION_COOKIE_SAMESITE"] = "None"
13
  app.config["SESSION_COOKIE_SECURE"] = True
@@ -78,8 +80,15 @@ def index():
78
  except Exception as e:
79
  return jsonify({"error": f"Database connection failed: {str(e)}", "format": "json"}), 500
80
 
81
- @app.route('/chat', methods=['POST'])
82
  def chat():
 
 
 
 
 
 
 
83
  data = request.json
84
 
85
  if 'DB_HOST' not in session:
 
1
  from flask import Flask, g, render_template, request, jsonify, session
2
+ from flask_cors import CORS # Add this import
3
  import os
4
 
5
  from helpers.GROQ import ConversationGROQ
 
9
  import pandas as pd
10
 
11
  app = Flask(__name__)
12
+ CORS(app, supports_credentials=True) # Add this line to enable CORS
13
  app.secret_key = os.urandom(24) # Set a secret key for session encryption
14
  app.config["SESSION_COOKIE_SAMESITE"] = "None"
15
  app.config["SESSION_COOKIE_SECURE"] = True
 
80
  except Exception as e:
81
  return jsonify({"error": f"Database connection failed: {str(e)}", "format": "json"}), 500
82
 
83
+ @app.route('/chat', methods=['POST', 'OPTIONS']) # Add OPTIONS method
84
  def chat():
85
+ if request.method == 'OPTIONS':
86
+ # Respond to preflight request
87
+ response = app.make_default_options_response()
88
+ response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
89
+ response.headers['Access-Control-Allow-Methods'] = 'POST'
90
+ return response
91
+
92
  data = request.json
93
 
94
  if 'DB_HOST' not in session: