angularjs - 使用 grunt-connect-proxy 的 Yeoman 返回 ECONNREFUSED 错误

标签 angularjs gruntjs yeoman

我正在尝试添加 grunt-connect-proxy到一个使用最新的 yeoman + Angular 生成器的项目。

但是,当到达应该转发的路径时(例如 127.0.0.1:9000/api/v1),服务器返回此错误:

An error has occurred: {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect"}

我使用了修改后的 Gruntfile:same as here按照建议。

我应该如何调试它?有没有人最近遇到过与 grunt-connect-proxy 类似的问题?

我也对代理 angular webapp 的 api 调用的类似解决方案感兴趣,如果您有任何实际可行的话。

谢谢你帮助我!非常感谢!

最佳答案

Gruntfile 没问题,错误是由您的后端引起的,即 localhost:3000(可能是 Rails)。

如果是Rails,就是CORS问题。您需要允许 Rails 接受来自 grunt 服务器的连接。将“rack-cors”添加到您的 gemfile 并在您的 development.rb 配置文件中像这样配置它:

config.middleware.use Rack::Cors do
  allow do
    origins 'localhost:9000'
    resource '*', :headers => :any, :methods => [:get, :post, :options, :delete]
  end
end

查看此链接了解详细设置,它帮助我让它正常工作。

Working with Angular.js and Rails

关于angularjs - 使用 grunt-connect-proxy 的 Yeoman 返回 ECONNREFUSED 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20092065/

相关文章:

node.js - Sequelize PostgresQL - 列不存在时

python - Angular : PUT, OPTIONS 方法的 Flask RESTful 跨域问题

css - 为什么 grunt-contrib-less 找不到 Bootstrap 变量?

gruntjs - 无法使 grunt-contrib-compass 工作

timeout - 504 运行时超时 'yo angular-fullstack:openshift'

node.js - 使用 yeoman 生成终极种子时出错

javascript - ng-cloak 无法正常工作

css - 在 CSS 中选择动态元素名称

node.js - 在windows服务上执行 "grunt serve"

yeoman - 在子生成器中使用 composeWith 选项