[英]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.