Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda