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

277
Vistas
How to fix CORS when making front-end API calls to localhost?

I have a Flask app that's split into front-end SPA (Vue.js) and back-end. But I'm having trouble with CORS.

In the front-end, I'm making API calls to //127.0.0.1:5000, which is what the back-end is listening to:

axios.put(
    '//127.0.0.1:5000/api/foo',
    formData,
    {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })

On the back-end, I set up CORS by using Flask-CORS just like everybody mentions. I'm also using Blueprints (if that makes any difference), and my router looks like this:

from flask_cors import CORS

api = Blueprint('api', __name__)
CORS(api)

@api.route('/api/foo', methods=['PUT'])
def foo():
   # etc...

In Firefox, I get an OPTIONS preflight request, then a console error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://127.0.0.1:5000/api/foo. (Reason: CORS request did not succeed). Status code: (null).

And on Chrome, I get this error:

PUT https://127.0.0.1:5000/api/foo net::ERR_CONNECTION_REFUSED

On my local machine, I have no problems. The issue happens on the instance I've deployed to Digitalocean. It has HTTPS enabled, so that shouldn't be an issue (I think). Any ideas? Do I need to change the call to localhost to something else? I feel like I've tried all the relevant suggestions regarding CORS.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

CORS middleware goes over Flask APP, not over blueprint

app = Flask(__name__)
CORS(app)
about 4 years ago · Santiago Gelvez Denunciar
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