Foreman/Puma isn't using the specified port in dev env

后端 未结 3 2038
旧时难觅i
旧时难觅i 2021-02-19 06:50

I set the port as 3000 in my application.yml (figaro managing env variables) rails s uses port 3000 but when I run foreman start (as recommended by Her

3条回答
  •  无人共我
    2021-02-19 07:11

    Mystery on the puma port solved.

    Put this print in your config/puma.rb

    Then you'll see that somehow the port is mysteriously set to 5000 even though it is not in your ENV.

    Fix at bottom.

    puma_port = ENV['PORT'] || 3000
    puts "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
    puts "puma_port is #{puma_port}"
    puts "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ”
    

    That prints out

    16:49:28 web.1  | ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
    16:49:28 web.1  | puma_port is 5000
    ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
    

    Then place this line in your Procfile (not the one you use for Heroku). I've got one called Procfile.dev

    web: PORT=3000 bundle exec puma -C config/puma.rb
    

    And I run it with this command:

    foreman start -f Procfile.dev
    

提交回复
热议问题