Cant set.header in express
<p>This stuff has been bugging me for days now and I am about to go crazy... I am not able to set.header('Access-Control-Allow-Origin') or any other header for that matter. I need this to access a remote API. I have downloaded the chrome cors extension and everything works when that is enabled. When I disable I get the beautiful error: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost:8080" rel="nofollow">http://localhost:8080</a>' is therefore not allowed access.</p>

<p>I have tried number of things and even the cors npm module, still the same.</p>

<p>This is my code:</p>

<pre><code>var express     = require('express');
var app         = express();

app.use('/dist', express.static(__dirname + '/dist'));


app.use(function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  next();
});

var port = process.env.PORT || 8080;


app.get('*', function(req, res, next) {
  console.log(req.get('Access-Control-Allow-Origin'));
  res.sendFile(__dirname + '/dist/index.html');
});


app.listen(port);
console.log('listen at ' + port);
</code></pre>