Class: Shikibu::Middleware::RackApp

Inherits:
Object
  • Object
show all
Defined in:
lib/shikibu/middleware/rack_app.rb

Overview

Rack application for handling CloudEvents

Examples:

config.ru

require 'shikibu'

Shikibu.configure do |config|
  config.database_url = ENV['DATABASE_URL']
  config.auto_migrate = true
end

Shikibu.app.register OrderSaga
Shikibu.app.start

run Shikibu::Middleware::RackApp.new

Rails middleware

# config/application.rb
config.middleware.use Shikibu::Middleware::RackApp

Constant Summary collapse

CONTENT_TYPE_JSON =
'application/json'
CONTENT_TYPE_CLOUDEVENTS =
'application/cloudevents+json'

Instance Method Summary collapse

Constructor Details

#initialize(app = nil) ⇒ RackApp

Returns a new instance of RackApp.



31
32
33
# File 'lib/shikibu/middleware/rack_app.rb', line 31

def initialize(app = nil)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/shikibu/middleware/rack_app.rb', line 35

def call(env)
  request = Rack::Request.new(env)
  path = request.path_info

  case path
  when '/shikibu/events', '/events'
    handle_event(request)
  when '/shikibu/health', '/health'
    health_check
  when '/shikibu/health/live', '/health/live'
    liveness_check
  when '/shikibu/health/ready', '/health/ready'
    readiness_check
  when %r{^/shikibu/workflows/([^/]+)/status$}
    handle_status(::Regexp.last_match(1))
  when %r{^/shikibu/workflows/([^/]+)/result$}
    handle_result(::Regexp.last_match(1))
  when %r{^/shikibu/workflows/([^/]+)/cancel$}
    handle_cancel(request, ::Regexp.last_match(1))
  else
    # Pass to next middleware if available
    @app ? @app.call(env) : not_found
  end
end