Can't launch simple Sinatra app using rackup and jRuby (no response from web server)

前端 未结 4 1511
梦谈多话
梦谈多话 2021-02-05 17:52

I\'ve got a Sinatra \"hello world\" app that I am trying to run using jRuby. It works when I run the app, but not when I run rackup. Can anyone tell me what is going on here?

相关标签:
4条回答
  • 2021-02-05 18:24
    #config.ru
    require "./app.rb"
    
    set :bind, '0.0.0.0'
    set :port, 9292 #set your port!
    Sinatra::Application.run!
    

    try this code and type rackup

    Then you can get the results you want.

    0 讨论(0)
  • 2021-02-05 18:37

    When you run the Ruby file directly (or when you add Sinatra.run! to the config.ru file) Sinatra runs its own server. In this case the call to set :bind, '0.0.0.0' will take effect. When you run through rackup this setting is ignored.

    The default host that rackup listens to is localhost, so the server will only be available through the same machine, you won’t be able to access it from other machines. To access it through other machines set the --host option:

    bundle exec rackup -p4567 --host 0.0.0.0
    

    (Note the output of rackup -h for the current version says the default host is 0.0.0.0, but this is out of date and has been fixed in master.)

    0 讨论(0)
  • 2021-02-05 18:42

    I have slightly similar situation. But the difference is that, my Jruby + Sinatra rackup app is finally starts responding.

    But it takes lots of time, sometimes it starts responding 5 minutes after app start. I found out, that after app start port is not listened for some period time.

    If we make netstat -an it will not show our app port. Actually I don't know the reason of such behavior, but I'll dig for it.

    0 讨论(0)
  • 2021-02-05 18:46

    Well, this is hardly sufficient to explain what is going on, but I can make it work if in config.ru I replace

    run Sinatra::Application
    

    with

    Sinatra::Application.run!
    

    In fact, knowing that makes me even more confused. Some sort of bug in Rack?

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