I want to write a simple flask call from react
App.js code:
import React, { useState, useEffect } from "react";
function App() {
...
useEffect(() => {
fetch(`http://127.0.0.1:5000/ `, {mode: "no-cors"}).then(response => response.json()).then(data => setResponseText(data.total));
}, [name]);
...
return (
...
);
}
export default App;
Flask code:
from flask import Flask, Response, jsonify
from flask_cors import CORS, cross_origin
app = Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'
CORS(app)
@app.route('/')
@cross_origin()
def hello_world(): # put application's code here
r = Response("text", status=200)
r.headers["Content-Type"] = "application/json"
r.headers['Access-Control-Allow-Origin'] = '*'
r.headers["Access-Control-Allow-Credentials"] = True
return r
if __name__ == '__main__':
app.run(debug=True)
and error in fetch: App.js:13 Uncaught (in promise) SyntaxError: Unexpected end of input
what am I doing wrong?