title: 'Access-Control-Allow-Origin' header error. The response had HTTP status code 503
body: <p>I built an api in ExpressJS + MongoDB. When I make a get/post request from Postman, everything works fine but when i request it from my javascript file I get an error : 503 (Service Unavailable) and  No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://127.0.0.1:5500" rel="nofollow noreferrer">http://127.0.0.1:5500</a>' is therefore not allowed access. The response had HTTP status code 503.</p>
  
  <p>My javascript file :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>function add_score(user,level,score){
    
    let xmlhttp = new XMLHttpRequest();
    const url = "http://tranquil-mountain-64247.herokuapp.com/api/scores";
  
    xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 &amp;&amp; this.status == 200) {
          console.log("sim");
      }
    };
    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send("user="+user+"&amp;level="+level+"&amp;time="+score);
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>My api file:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>var express = require('express');
  var app = express();
  var bodyParser = require('body-parser');
  var mongoose = require('mongoose');
  
  app.use(bodyParser.json());
  
  mongoose.connect("mongodb://...");
  
  app.get('/api/scores', (req,res) =&gt; {
      Score.getScores((err, scores) =&gt; {
          if (err){
              throw err;
          }
          res.json(scores);
      })
  
  });
  
  app.post('/api/scores', (req, res) =&gt; {
   var score = req.body;
   Score.addScore(score, (err, score) =&gt; {
    if(err){
     throw err;
    }
    res.json(score);
   });
  });</code></pre>
  </div>
  </div>
  </p>