jekyll / jekyll-admin

A Jekyll plugin that provides users with a traditional CMS-style graphical interface to author content and administer Jekyll sites.
https://jekyll.github.io/jekyll-admin/
MIT License
2.83k stars 359 forks source link

incompatible with sinatra 4.0 / rack 3.0 #705

Open namiwang opened 7 months ago

namiwang commented 7 months ago

After upgrading sinatra (which jekyll-admin depends on) to 4.0, got the following error when staring server

bundler: failed to load command: jekyll (/Users/nami/.asdf/installs/ruby/3.2.2/bin/jekyll)
<internal:/Users/nami/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require': cannot load such file -- rack/handler (LoadError)
    from <internal:/Users/nami/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from /Users/nami/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/jekyll-admin-0.11.1/lib/jekyll/commands/serve.rb:23:in `jekyll_admin_monkey_patch'
    from /Users/nami/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/jekyll-admin-0.11.1/lib/jekyll/commands/serve.rb:15:in `start_up_webrick'
...

The root cause is sinatra 4 dropped support for rack 2

refs:

A workaround is to add gem "rackup" to Gemfile.

A simple fix would be limiting spec.add_dependency "sinatra", ">= 1.4", "< 4.0" in gemspec, or adding rackup as a direct dependency.

kebugcheckex commented 6 months ago

Github Dependabot sent me multiple security alerts regarding rack version used in jekyll-admin. rack should be upgraded to at least 2.2.8.1. Upgrading sinatra to 4 will solve the problem.

yuanworks commented 4 months ago

@namiwang unfortunately your fix (adding rackup gem) doesn't let me save new pages inside the admin because of the following error:

 NoMethodError - undefined method `rewind' for #<Rackup::Handler::WEBrick::Input

I managed to get both admin and saving files working by downgrading sinatra:

gem "sinatra", ">= 3", "< 4"

Edit: issue mentioned here too https://github.com/jekyll/jekyll-admin/issues/709

philosophicles commented 3 months ago

I've had similar but not identical issues today after forking from an old jekyll theme, switching on dependabot, and it asking for some massive version leaps in both rack and jekyll-admin.

jekyll 3.9.5 | Error:  uninitialized constant Rack::Handler
/usr/local/lib/ruby/gems/3.3.0/gems/jekyll-admin-0.11.1/lib/jekyll/commands/serve.rb:23:in `jekyll_admin_monkey_patch': uninitialized constant Rack::Handler (NameError)

          @server.mount "/admin", Rack::Handler::WEBrick, JekyllAdmin::StaticServer
                                      ^^^^^^^^^
    from /usr/local/lib/ruby/gems/3.3.0/gems/jekyll-admin-0.11.1/lib/jekyll/commands/serve.rb:15:in `start_up_webrick'
    from /usr/local/lib/ruby/gems/3.3.0/gems/jekyll-3.9.5/lib/jekyll/commands/serve.rb:104:in `process'
...

Thanks @yuanworks : after trying various other fix suggestions from around the internet, downgrading sinatra to 3.x (3.2.0 specifically) did the trick for me.

I am not normally a ruby person and a little lost in this dependency mire, but commenting in case this helps anyone else out.

pboling commented 1 week ago

Here's the answer (most likely).

You need to add the rackup gem to your dependencies in order to be compatible with rack v3.

gem "rackup"
pboling commented 1 week ago

@yuanworks You would also need to replace your line that looks like this:

Rack::Handler::WEBrick.run server

with a line that looks like this:

Rackup::Server.start app: server

where server is something like:

server = Rack::Builder.new do 
  # ...
end

Note: it will still run WEBrick.