繁体   English   中英

Heroku上的Meteor移动服务器-不存在Access-Control-Allow-Origin标头

[英]Meteor Mobile Server on Heroku - No Access-Control-Allow-Origin header is present

首先,我说我在网上找到了几个建议的解决方案,但是似乎没有一个适合我。

问题:

我有一个流星应用程序,我试图在android上运行。 为此,我将应用程序部署在Heroku上,并使用--mobile-server https://myapp.heroku.com参数调用run android-device命令。

我永久收到错误

"XMLHttpRequest cannot load https://myapp.heroku.com/sockjs/... . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:12848' is therefore not allowed access. The response had HTTP status code 404.", source: http://localhost:12848/ (0)

到目前为止,这是我尝试过的:

我在流星启动时设置了ROOT URL:

  process.env.ROOT_URL = "https://myapp.heroku.com";  

我尝试在流星启动时在服务器端这样设置访问控制:

  WebApp.connectHandlers.use(function(req, res, next) {
    res.setHeader("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
    res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
    res.header('Access-Control-Allow-Origin', 'https://myapp.heroku.com');
    res.header('Access-Control-Allow-Origin', 'http://localhost:12848');
    res.header('Access-Control-Allow-Origin', 'http://meteor.local');
    res.header("Access-Control-Allow-Headers", "Content-type,Accept,X-Custom-Header");
    return next();
  });

我试图在流星启动时在服务器端使用这种浏览器策略包:

  BrowserPolicy.content.allowSameOriginForAll();
  BrowserPolicy.content.allowOriginForAll('*');
  BrowserPolicy.content.allowOriginForAll('http://meteor.local');
  BrowserPolicy.content.allowOriginForAll('https://myapp.heroku.com');
  BrowserPolicy.content.allowOriginForAll('https://*.myapp.heroku.com');
  BrowserPolicy.content.allowEval();

我尝试将访问规则添加到“ mobile-config.js”:

App.accessRule("*");

我确保根目录下“ package.json”文件中的名称与“ mobile-config.js”下的应用程序名称相同

我还想念什么?

编辑:

我也尝试过将express和cors软件包添加到本地主机白名单中:

  var whitelist = [
  'http://localhost:3000',
  'http://localhost:12848',
  'https://myapp.heroku.com'
  ];
  var corsOptions = {
      origin: function(origin, callback){
          var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
          callback(null, originIsWhitelisted);
      },
      credentials: true
  };
  app.use(cors(corsOptions));

还尝试启用预检,如下所示:

app.options('*', cors())

这可能是我遇到过的最愚蠢的问题。 尝试使用--mobile-server https://myapp.heroku.com参数运行该应用程序是错误的。 相反,它应该是https://myapp.herokuapp.com

就是这样 一直就是问题所在...

在白名单中添加“ *”即可完成此工作。 最终解决方案位于config.xml中,这应该会有所帮助: https : //stackoverflow.com/a/36124935/8056323

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM