【问题标题】:Foreman not working with a rake tast on rails工头没有在铁轨上使用耙子
【发布时间】:2018-10-10 14:07:39
【问题描述】:

所以我的 rails 后端在 3001 端口运行,并且 React 前端可能在 3000 端口运行。

我想设置一个简单的rake start 任务来启动两者。

为此,我使用了foreman gem,它在我运行时完美运行:foreman start -f Procfile.dev

但是:当我运行我的任务时:rake start,我收到以下错误:

Running via Spring preloader in process 36257
15:56:57 web.1  | started with pid 36258
15:56:57 api.1  | started with pid 36259
15:56:57 api.1  | /usr/local/opt/rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/foreman-0.64.0/bin/foreman-runner: line 41: exec: PORT=3001: not found
15:56:57 api.1  | exited with code 127
15:56:57 system | sending SIGTERM to all processes
15:56:57 web.1  | terminated by SIGTERM

这是我的start.rake 文件:

namespace :start do
  desc 'Start dev server'
  task :development do
    exec 'foreman start -f Procfile.dev'
  end

  desc 'Start production server'
  task :production do
    exec 'NPM_CONFIG_PRODUCTION=true npm run postinstall && foreman start'
  end
end
task :start => 'start:development'

还有我的Procfile.dev 文件:

web: cd client && PORT=3000 npm start
api: PORT=3001 && bundle exec rails s

有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails reactjs foreman


    【解决方案1】:

    我遇到了同样的问题。我不知道为什么,但是当工头从 rake 运行时,它无法在同一行上处理多个命令,例如

    web: cd client && PORT=3000 npm start
    

    为了解决这个问题,我将我的 Procfile.dev 更改为

    web: npm start --prefix client
    api: bundle exec rails s -p 3001
    

    在我的 package.json 中,我改变了

    "scripts": {
        "start": "react-scripts start",
        ...
    }
    

    "scripts": {
        "start": "PORT=3000 react-scripts start",
        ...
    }
    

    这允许您为 react 和 rails 服务器指定端口,并且两者都可以正常工作

    foreman start -f Procfile.devrake start

    【讨论】:

      【解决方案2】:

      我不认识 Foreman,但每天早上我都会使用 teamocil 启动我的开发环境。这是一个example 文件。

      为您的 .bash_alias 文件添加别名:

       alias s2="cd /home/manuel/chipotle/schnell && tmux new-session -d 'teamocil schnell' \; attach"
      

      所以您只需在控制台中输入“s2”,包括数据库提示在内的所有内容都已启动并准备就绪。

      【讨论】:

        【解决方案3】:

        我知道我有点晚了,但本质上你不应该使用多行命令,总是尽量避免。您可以更改语法并使用一些标志使其在线:

        web: npm start --port 3000 --prefix client 
        api: bundle exec rails s -p 3001
        

        我希望它可以帮助任何面临同样问题的人。 快乐编码

        【讨论】:

          猜你喜欢
          • 2012-04-07
          • 1970-01-01
          • 2011-11-14
          • 2018-02-09
          • 2023-03-18
          • 2011-12-06
          • 2016-09-25
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多