title: Allowing frontend JavaScript POST requests to https://accounts.spotify.com/api/token endpoint
body: <p>In order to get an access token for the Spotify API in my web app (as specified by their Web Authorization Flow), I've learned that I have to make a <code>POST</code> request. However, when I do so, I get the <code>XMLHttpRequest</code> <code>500 Error</code> due to the cross-origin problem.</p>
  
  <p>I have already figured out how to allow CORS <code>GET</code> requests, but am not sure how to do the same for <code>POST</code> requests. <a href="http://enable-cors.org/server_expressjs.html" rel="nofollow">This link</a> provides configuration tips, but it leaves the actual routes for <code>GET</code> and <code>POST</code> blank.</p>
  
  <p>This is the relevant code for my Express.js server:</p>
  
  <pre><code>app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
  });
  
  
  
  app.use(express.static(__dirname + '/public')); // looks in public directory, not root directory (protects files)
  
  app.get('/', function(req, res) {
    // res.header("Access-Control-Allow-Origin", "*");
    // res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.send(__dirname + '\\index.html')
  });
  
  app.post('/', function(req, res) {
      res.send(req.body.spotify);
  });
  </code></pre>
  
  <p>(<code>spotify</code> is the <code>spotify-web-api-js</code> node module).</p>
  
  <p>I've previously tried copying the exact code for <code>app.get</code> into <code>app.post</code>, but that caused the server to crash.</p>
  
  <p>This is the bit of code in my program's JavaScript file that intends to send a <code>POST</code> request after the user clicks on a button that takes them to the start of Spotify's authorization path and approves the sign-in:</p>
  
  <pre><code>$('#spotify').on('click', function() {
      $.support.cors = true;
  
      $.post("https://accounts.spotify.com/api/token");
  
        });
  </code></pre>
  
  <p>(in this case, <code>spotify</code> is the ID for the button in the HTML file)</p>
  
  <p>What should I do to bypass the CORS issue in this case? I've been stumped for a few days.</p>