Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Problem with call flask endpoint from react

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!