【问题标题】:Ember CLI and Rails: Error proxying to http://localhost:3000Ember CLI 和 Rails:代理到 http://localhost:3000 时出错
【发布时间】:2016-04-05 21:20:14
【问题描述】:

我正在关注 Ember CLI 和 Rails 的 this tutorial。我被困在你应该在控制台中使用以下命令加载 Book 模型数据的地方:

App.store.findAll('book');

未检索到数据,Ember 终端日志显示此错误:

Error proxying to http://localhost:3000
connect ECONNREFUSED 127.0.0.1:3000
Error: connect ECONNREFUSED 127.0.0.1:3000
    at Object.exports._errnoException (util.js:890:11)
    at exports._exceptionWithHostPort (util.js:913:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1061:14)
GET /books - - ms - -

但是,当我访问 http://localhost:3000/books(Rails 后端)时,我得到了所有书籍的正确 JSON 响应。为什么 Ember 应用无法检索此数据,我该如何解决?

【问题讨论】:

  • 我目前将 Rails 后端和 Ember 应用程序放在 2 个单独的文件夹中。这可能是其中的一部分吗?我应该将 Ember 应用程序移动到 Rails 根文件夹的子文件夹中吗?
  • 不。我运行了几个 Ember+Rails 应用程序。请看下面我的回答。这应该可以解决问题。

标签: ruby-on-rails ember.js http-proxy


【解决方案1】:

重启 Rails 服务器:

rails s --binding 0.0.0.0

然后重新启动 ember 服务器。

【讨论】:

  • 我不再在这个项目中使用 Ember,所以我无法对此进行测试,但这听起来可能已经解决了我的问题,所以除非有任何反对意见,否则我会将其标记为已接受。
【解决方案2】:

有很多事情你需要看。

  1. 尝试在您的 embers config/environment.js 中为每个环境设置正确的 URL 和设置。更多信息here

      ENV.contentSecurityPolicy = {
        'default-src': "'none'",
        'script-src': "'self'",
        'font-src': "'self'",
        'connect-src': "'self' http://localhost:3000",
        'img-src': "'self' data:",
        'style-src': "'self' 'unsafe-inline'",
        'media-src': "'self'"
    };
    
  2. 您还需要解释 Rails 应用程序以接受 Rails 应用程序之外的连接。 CORS。寻找this gem

【讨论】:

  • 感谢您的回复。我按照您的建议添加了内容安全策略,并在 Rails 中启用了 CORS 并允许一切(来源'',资源'',...),但我仍然遇到同样的错误。 Rails 日志中没有任何请求进入和/或被阻止的迹象。
  • 您能发布您的 embers 适配器吗? application.js 或 book.js 如果您要覆盖任何内容。
猜你喜欢
  • 2021-09-28
  • 2023-02-02
  • 2019-07-07
  • 2018-10-28
  • 2018-11-26
  • 1970-01-01
  • 2020-01-31
  • 2018-10-10
  • 1970-01-01
相关资源
最近更新 更多