简体   繁体   English

Ionic2与流星

[英]Ionic2 with Meteor

I have a problem using Meteor in an Ionic2 project. 我在Ionic2项目中使用Meteor时遇到问题。 The project itself should run, as it is a clone of the Meteor-tutorial: git clone https://github.com/Urigo/Ionic2CLI-Meteor-WhatsApp 该项目本身应该运行,因为它是Meteor-tutorial的git clone https://github.com/Urigo/Ionic2CLI-Meteor-WhatsAppgit clone https://github.com/Urigo/Ionic2CLI-Meteor-WhatsApp

When I start the Meteor server I get this 当我启动Meteor服务器时,我得到了

=> Started proxy.                             
server/publications.ts (24, 10): Property 'publishComposite' does not exist on type 'typeof Meteor'.
server/main.ts (14, 28): Property '_options' does not exist on type 'typeof Accounts'.
server/main.ts (51, 14): Property 'createUserWithPhone' does not exist on type 'typeof Accounts'.
=> Started MongoDB.                           
=> Started your app.                          

=> App running at: http://localhost:3000/

Then I start the ionic app with ionic serve and get this in the terminal 然后我用ionic serve启动离子应用,并在终端中获取

Running live reload server: http://localhost:35729
Watching: www/**/*, !www/lib/**/*, !www/**/*.map
√ Running dev server:  http://localhost:8100

When I open the App I get this error in the browser's console: 当我打开应用程序时,我在浏览器的控制台中收到此错误:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8100/sockjs/info?cb=_07sz35uj7

As I understand it means that it tries to grab data from meteor but couldn't reach it. 据我了解,这意味着它试图从流星获取数据,但无法到达。 When I open the URL in the browser manually and change the port to 3000 I get back a message from meteor. 当我在浏览器中手动打开URL并将端口更改为3000我收到了来自流星的消息。

I found two hints on Google: 我在Google上找到了两个提示:

1) start the ionic app without livereload ionic serve --nolivereload 1)在没有livereload ionic serve --nolivereload情况下启动离子应用程序ionic serve --nolivereload

2) to set __meteor_runtime_config__ to the correct URL:PORT 2)将__meteor_runtime_config__设置为正确的URL:PORT

But hint 1 doesn't work and for hint 2 I have no idea where to place it. 但是提示1不起作用,对于提示2,我不知道将其放置在何处。

While writing this I found out, that in the file node_modules/meteor-client-side/meteor-runtime-config.js the correct port is defined by 在编写此文件时,我发现在文件node_modules/meteor-client-side/meteor-runtime-config.js ,正确的端口由

__meteor_runtime_config__ = {};
__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL = 'http://localhost:3000';

So it looks like hint 2 is also already done. 因此,提示2似乎也已完成。 Why is it still trying to reach the meteor server on wrong port, or is there maybe another problem? 为什么它仍然试图通过错误的端口访问流星服务器,或者可能还有另一个问题?

Ok, solved it on my own again. 好的,我自己再解决一次。 I had to add those lines of code to the index.html file of my ionic2 project: 我必须将这些代码行添加到ionic2项目的index.html文件中:

<script>
    __meteor_runtime_config__ = {
      DDP_DEFAULT_CONNECTION_URL: 'http://localhost:3000'
    };
</script>

No idea, why the config in the node_modules/meteor-client-side/meteor-runtime-config.js file is ignored. 不知道,为什么会node_modules/meteor-client-side/meteor-runtime-config.js文件中的配置。

Edit: Looks like there was a bug that is fixed in version 1.3.5 https://github.com/idanwe/meteor-client-side/issues/28#issuecomment-263252756 编辑:似乎有一个错误已在1.3.5版中修复https://github.com/idanwe/meteor-client-side/issues/28#issuecomment-263252756

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

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