How to make CORS in Meteor.js application working?


I’m trying for few hours to send a POST request from simple index.html page, using Ajax as bellow:

type: 'POST',
url: '',
crossDomain: true,
data: {"some":"json"},
dataType: 'json',
success: function(responseData, textStatus, jqXHR) {
    var value = responseData.someKey;
error: function (responseData, textStatus, errorThrown) {
    alert('POST failed.');

Code in my meteorapp.js:

 if (Meteor.isServer) {

  var connectHandler = WebApp.connectHandlers; // get meteor-core's connect-implementation

  Meteor.startup(function () {
    connectHandler.use(function (req, res, next) {
      res.setHeader('Access-Control-Allow-Origin', '');
      res.setHeader('Access-Control-Allow-Methods', ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS']);
      res.setHeader('Access-Control-Max-Age', '1000');
      res.setHeader('Access-Control-Allow-Headers', ['Content-Type', 'Authorization', 'X-Requested-With']);
      return next();
  }); - this and many others pages say that my solution should work, so please. Can someone review my code and show me what is wrong with it.


If I change my origin domain to ‘’ than I get following error i the console:

For the ‘

XMLHttpRequest cannot load
The ‘Access-Control-Allow-Origin’ header contains the invalid value’. Origin ‘’ is therefore not
allowed access.

and for the ‘*’ I’m still getting a fail pop-up.


Logged this error:

SyntaxError: Unexpected token <
at Object.parse (native)
at m.parseJSON (
at Pb (
at x (
at XMLHttpRequest.b (