简体   繁体   English

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

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

Let me start by saying I've found several proposed solutions online, but none of them seem to work for me. 首先,我说我在网上找到了几个建议的解决方案,但是似乎没有一个适合我。

Issue: 问题:

I have a meteor app I'm trying to run on android. 我有一个流星应用程序,我试图在android上运行。 For this, I've deployed the app on Heroku and I call the run android-device command using the --mobile-server https://myapp.heroku.com parameter. 为此,我将应用程序部署在Heroku上,并使用--mobile-server https://myapp.heroku.com参数调用run android-device命令。

I permanently receive the error 我永久收到错误

"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)

Here is what I've tried so far: 到目前为止,这是我尝试过的:

I set ROOT URL at meteor startup: 我在流星启动时设置了ROOT URL:

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

I tried setting the Access Control like this, server-side at meteor startup: 我尝试在流星启动时在服务器端这样设置访问控制:

  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();
  });

I tried to use the browser-policy package, like this, server-side at meteor startup: 我试图在流星启动时在服务器端使用这种浏览器策略包:

  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();

I tried adding access rules to "mobile-config.js": 我尝试将访问规则添加到“ mobile-config.js”:

App.accessRule("*");

I made sure the name in the "package.json" file under root is identical to the App name under "mobile-config.js" 我确保根目录下“ package.json”文件中的名称与“ mobile-config.js”下的应用程序名称相同

What else am I missing? 我还想念什么?

Edit: 编辑:

I've also tried adding the express and cors packages to whitelist local host: 我也尝试过将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));

Also tried to enable pre-flight, like this: 还尝试启用预检,如下所示:

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

This is probably the stupidest problem I ever ran into. 这可能是我遇到过的最愚蠢的问题。 Trying to run the app using the --mobile-server https://myapp.heroku.com parameter was wrong. 尝试使用--mobile-server https://myapp.heroku.com参数运行该应用程序是错误的。 Instead, it should be https://myapp.herokuapp.com 相反,它应该是https://myapp.herokuapp.com

That was it. 就是这样 That was the problem all along... 一直就是问题所在...

Adding '*' to whitelist should do the job. 在白名单中添加“ *”即可完成此工作。 The ultimate solution lies within config.xml, this should be helpful: https://stackoverflow.com/a/36124935/8056323 最终解决方案位于config.xml中,这应该会有所帮助: https : //stackoverflow.com/a/36124935/8056323

暂无
暂无

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

相关问题 ionic:请求的资源上不存在“ Access-Control-Allow-Origin”标头 - ionic: No 'Access-Control-Allow-Origin' header is present on the requested resource WebView不存在“ Access-Control-Allow-Origin”标头[ANDROID] - WebView No 'Access-Control-Allow-Origin' header is present [ANDROID] 模型查看器颤动请求的资源上不存在“Access-Control-Allow-Origin”标头 - modelviewer flutter No 'Access-Control-Allow-Origin' header is present on the requested resource Android WebView“请求的资源上不存在'Access-Control-Allow-Origin'标头” - Android WebView “No 'Access-Control-Allow-Origin' header is present on the requested resource” Google Cast:加载元数据错误并且不存在Access-Control-Allow-Origin标头 - Google Cast: Load Metadata Error and No Access-Control-Allow-Origin header is present JSON_2_Region.json。 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问原始“空”。 - JSON_2_Region.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. webview-访问控制允许原点不允许原点(使用cordova将angular转换为mobile) - webview - origin is not allowed by access-control-allow-origin (convert angular to mobile using cordova) 科尔多瓦没有访问控制允许来源 - cordova No Access-Control-Allow-Origin 如何解决“ CORS策略:“ Access-Control-Allow-Origin”标头的值不等于提供的来源。” - How to solve "CORS policy: The 'Access-Control-Allow-Origin' header has a value that is not equal to the supplied origin.'? android webview - 访问控制允许来源 - android webview - Access-Control-Allow-Origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM