title: React and Flask with Socket.IO - CORS problem
body: <p>I'm trying to make a <strong>Flask server</strong> (port 5000) that has a socket.io connection with a <strong>React client</strong> (port 3000). When I try to execute the server script (shown below), I get an error that says &quot;<strong>http://localhost:3000 is not an accepted origin</strong>&quot; even though I am using CORS.</p>
  <p>server-test.py:</p>
  <pre class="lang-py prettyprint-override"><code>from flask import Flask
  from flask_socketio import SocketIO, emit
  from flask_cors import CORS, cross_origin
  
  import os
  from dotenv import load_dotenv, find_dotenv
  load_dotenv(find_dotenv())
  
  app = Flask(__name__)
  app.config['CORS_HEADERS'] = 'Content-Type'
  app.config['SECRET_KEY'] = os.environ.get('SECRET')
  socketio = SocketIO(app)
  CORS(app)
  
  @socketio.on('connect')
  @cross_origin()
  def handle_connection():
    emit('server-client', 'Test message')
  
  
  @socketio.on('client-server')
  @cross_origin()
  def handle_client_msg(msg):
    print(&quot;\n&quot; + str(msg))
  
  
  if __name__ == '__main__':
    app.run(host=&quot;localhost&quot;, port=os.environ.get('PORT'))
    socketio.run(app)
  </code></pre>
  <p>App.jsx:</p>
  <pre class="lang-js prettyprint-override"><code>import { io } from 'socket.io-client';
  
  // ...
  
  useEffect(() =&gt; {
    const socket = io('http://localhost:5000');
  
    socket.on('server-client', msg =&gt; {
      alert(msg);
      socket.emit('client-server', 'Client: Message received!');
    });
  }, []);
  </code></pre>
  <p>Error message in WSL terminal:</p>
  <pre><code> * Serving Flask app 'server-test' (lazy loading)
   * Environment: production
     WARNING: This is a development server. Do not use it in a production deployment.
     Use a production WSGI server instead.
   * Debug mode: off
   * Running on http://localhost:5000/ (Press CTRL+C to quit)
  http://localhost:3000 is not an accepted origin. (further occurrences of this error will be logged with level INFO)
  127.0.0.1 - - [16/May/2021 00:27:31] &quot;GET /socket.io/?EIO=4&amp;transport=polling&amp;t=NboMpZQ HTTP/1.1&quot; 400 -
  127.0.0.1 - - [16/May/2021 00:27:31] &quot;GET /socket.io/?EIO=4&amp;transport=polling&amp;t=NboMpZS HTTP/1.1&quot; 400 -
  127.0.0.1 - - [16/May/2021 00:27:31] &quot;GET /socket.io/?EIO=4&amp;transport=polling&amp;t=NboMpZR.0 HTTP/1.1&quot; 400 -
  127.0.0.1 - - [16/May/2021 00:27:31] &quot;GET /socket.io/?EIO=4&amp;transport=polling&amp;t=NboMpZR HTTP/1.1&quot; 400 -
  </code></pre>