I'm getting this message when working on the POST method on my frontend. The weird thing is that for the GET method, I'm receiving all the data without cors issues. Do I have to change something?
Back end
app = Flask(__name__)
CORS(app, supports_credentials=True)
mysql = MySQL(app)
@app.route('/addContact', methods=['POST'])
@cross_origin(supports_credentials=True)
def addContact():
if request.method == 'POST':
firstname = request.form.get('firstname')
lastname = request.form.get('lastname')
birthday = request.form.get('birthday')
conn = mysql.connection
cur = conn.cursor()
cur.execute(
"INSERT INTO `farm-users`.users VALUES (DEFAULT, {}, {}, {})".format(firstname, lastname, birthday))
conn.commit()
return 'success'
Front end
const addUser = (e) => {
e.preventDefault()
createUser = {"firstname": firstname, "lastname": lastname,"birthday": birthday}
const requestOptions = {
method: 'POST',
headers: { 'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods':'GET,PUT,POST,DELETE,PATCH,OPTIONS',
'Content-Type': 'application/json',
'Access-Control-Allow-Headers': '*'
},
body: createUser
};
const res = fetch('http://127.0.0.1:3000/addContact', requestOptions)
console.log(res)
}
