`': superclass mismatch for class Server (TypeError)

前端 未结 3 823
时光取名叫无心
时光取名叫无心 2021-01-06 07:47

I have seen this and several others question, but their problems are not similar to mine.

I have added the following code to the config/boot.rb , to run

相关标签:
3条回答
  • 2021-01-06 08:12

    For Rails 5.1 the following line in config/boot.rb will do the trick:

    ENV['PORT'] = '8081'
    

    Link to the source.

    0 讨论(0)
  • 2021-01-06 08:25

    A better way to do what you want:

    require 'rails/commands/server'
    
    module DefaultOptions
      def default_options
        super.merge!(Port: 8081)
      end
    end
    
    Rails::Server.prepend(DefaultOptions)
    

    The reason for the error message is because you are attempting to redefine the Rails::Server class and changing it's inheritance structure. Rails::Server inherits from ::Rack::Server, however your code is trying to say it no longer does. Therefore, you get your superclass mismatch error.

    0 讨论(0)
  • 2021-01-06 08:27

    In Rails 5.2

    in config/puma.rb I added this code.

    #port        ENV.fetch("PORT") { 3000 }
    bind        'tcp://0.0.0.0:3001'
    

    And it works!

    0 讨论(0)
提交回复
热议问题