I’m testing to fetch data from client to server that i host by Vercel
the code of server is : from flask import Flask, request, jsonify
`from flask_cors import CORS
app = Flask(name)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
@app.route('/')
def hello_world():
return "test"
@app.route('/submit', methods=['POST'])
def submit():
data = request.json['data']
# print(data)
return jsonify({'message': f'Received:{data}'})
if __name__ == '__main__':
app.run()`
when i host by Vercel i got the link to the server is : https://cc-sqobm4548-tqtcses-projects.vercel.app
And the code from client that send data to the server is :
`
function submit(){
data = document.getElementById('data').value
console.log(data)
fetch('https://cc-sqobm4548-tqtcses-projects.vercel.app/submit',{
method: 'POST',
headers:{
'Content-Type': 'application/json'
},
body: JSON.stringify({data: data})
})
.then(response => response.json())
.then(data => console.log(data.message))
.catch(error => console.error('Error:', error))
}
</script>`
i have tested when i host local the server and it respone what i am expecting that the server respone the api submit, but when i host server on vercel i have the issue that it say fail to fetch, i dont know what wrong and how to fix