-1

I've got a React app with Flask on the backend in production and I found out that none of my endpoints are reached from React.

I'm aware that when using client-side routing developer needs to use a catch-all function similar to the below:

@app.errorhandler(404)
def error_handler(e):
    return render_template('index.html')

I'm using Flask-CORS to handle cross origin requests:

within config.py:

class ProductionConfig:
    CORS_HEADERS = 'Content-Type'
    ...
    ...

my blueprint:

CORS(auth_blueprint, resources={r'/*': {"origins": "https://example.com", "allow_headers": "*", "expose_headers": "*"}})

@auth_blueprint.route('/auth/login', methods=['POST'])
@cross_origin()
def login():
    ...
    ...

on the frondend I'm defining headers like this:

const headers = { "Access-Control-Allow-Origin": "*" };
const url = "https://example.com:5000/auth/login";
axios.post(url, data, headers).then(resp => { ... })

And I'm not getting any errors whatsoever. Server's logs are clean and the console only shows Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://example.com:5000/auth/login. (Reason: CORS request did not succeed). "Reason: CORS request did not succeed" means that the server didn't return anything. The app renders fine however React (axios) can't reach my endpoints. Are there any gotchas I'm not aware of ? When request is sent I'm not even getting a status code in the network tab.

Thank you.

Screenshot of the network tab:

enter image description here

1 Answers1

-3

You need to change the connection protocol to http.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Evgeniy
  • 303
  • 2
  • 9