Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Web UI #12

Closed
mperham opened this issue May 31, 2016 · 6 comments
Closed

Add Web UI #12

mperham opened this issue May 31, 2016 · 6 comments

Comments

@mperham
Copy link
Collaborator

mperham commented May 31, 2016

Sidekiq's Web UI is based on Sinatra. Investigate building a native Crystal version using Kemal and ecr views instead.

Requires #11.

@sdogruyol
Copy link

I'd be happy to help you about any Kemal related question 👍

@mperham
Copy link
Collaborator Author

mperham commented Jun 3, 2016

The top-level DSL seems really cool at first glance but IMO it takes away a lot of capabilities. I'm really missing a more idiomatic OOP-based webapp style. Sinatra now provides something like this:

class Sidekiq::Web < Kemal::Base
  public_folder "..."

  get "/" do |env|
  end
end

# Allow multiple webapps to be mounted
Kemal.serve("localhost", 8080, {
  "/sidekiq" => Sidekiq::Web
  "/something-else" => Another::Web
})

With that style, you could also implement testing helpers, a la Rack::Test:

require "kemal/spec"

def app
  Sidekiq::Web
end

describe "web" do
  it "should work" do
    resp = app.route(:get, "/")
    resp.code.should eq(200)
  end
end

@sdogruyol
Copy link

Yeah, i'm pretty aware of that and would like to implement the classic Sinatra style which lets you mount multiple apps.

@mperham
Copy link
Collaborator Author

mperham commented Jun 9, 2016

Done!

I was able to implement GET and POST helper methods to make the Ruby port easier. Allows me to spec like this:

    post "/scheduled/#{job_params(*params)}", {"add_to_queue" => "true"}
    assert_equal 302, last_response.status_code
    assert_equal "/scheduled", last_response.headers["Location"]

    get "/queues/default"
    assert_equal 200, last_response.status_code
    assert_match(/#{params.first["args"][2].to_s}/, last_response.body)

@mperham mperham closed this as completed Jun 9, 2016
@danielpclark
Copy link

danielpclark commented Apr 13, 2017

# Allow multiple webapps to be mounted
Kemal.serve("localhost", 8080, {
  "/sidekiq" => Sidekiq::Web
  "/something-else" => Another::Web
})

Did this get implemented in a mountable way for Kemal? I've been writing Rails-like controllers with Kemal in danielpclark/crystal-rails-template

require "../app/controllers/*"

module Railslike
  module Routes
    include Controllers
    get "/", &IndexController.to_proc
    error 404, &Error404Controller.to_proc
  end
end

Where each method I define (to_proc in this instance) returns something like:

def self.to_proc
  ->(env : HTTP::Server::Context){
    controller = new(env)         # Evaluated in other controller context of type BaseController
    controller.render(controller) # Pass context into layout renderer
  }   
end 

This works very well for me. But I digress, has this been implemented to run Sidekiq mounted in an existing server instance of Kemal?

@sdogruyol
Copy link

@danielpclark unfortunately, this is not implemented. Kemal only allows single app per single process (for now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants