title: How to connect backend (python, flask) with frontend (html, css, javascript)
body: <p>Info: for backend I'm using python with flask (for the moment it accepts http get methods) and for frontend I'm using html, css and javascript.</p>
  
  <p>Problem: I'm trying to make a http request (first time I tried POST and then GET) but the browser did not allow me to do that: "Access to XMLHttpRequest at 'localhost:5000/test' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.".</p>
  
  <p>What another choices do I have? (I would like some simple choices, it is just a homework).</p>
  
  <p>I've tried to make http POST and GET request.
  I've read that I cannot make http request from browser.
  I've read that I need (for example) an apache server. - too complicated, I need something more simple.
  I've tried: <a href="https://flask-cors.readthedocs.io/en/latest/" rel="nofollow noreferrer">https://flask-cors.readthedocs.io/en/latest/</a></p>
  
  <pre><code>document.getElementById("btn").addEventListener('click', add);
  function add()
  {
      const url = "localhost:5000/test";
      const http = new XMLHttpRequest();
      http.open("GET", url);
      http.send();
      http.onreadystatechange=(e)=&gt; {
          console.log(http.responseText)
      }
  }
  </code></pre>
  
  <pre><code>from flask import Flask
  from flask_cors import CORS
  from flask import request
  from flask import jsonify
  import json
  import mysql.connector
  import random
  import string
  import time
  
  time.sleep(3)
  app = Flask(__name__)
  
  @app.route("/test")
  def test():
      return "It's working"
  
  
  if __name__ == "__main__":
      app.run(host='0.0.0.0', port=5000)
  </code></pre>
  
  <p>I expect that in the browser console to be printed message: "It's working", but I get the error:
  Access to XMLHttpRequest at 'localhost:5000/test' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.</p>
  
  <p>LE: Flask server is inside a docker container. Ports are mapped "5000:5000'.</p>