Guest User

Untitled

a guest
Dec 9th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. require 'octarine'
  2. require 'reel'
  3.  
  4. module Reel
  5. module App
  6. def self.included(base)
  7. base.class_eval do
  8. include Octarine::App
  9.  
  10. attr_accessor :server
  11. end
  12. end
  13.  
  14. def initialize(host, port)
  15. super()
  16. @server = Reel::Server.supervise host, port do |connection|
  17. if connection.request # why is this nil sometimes?
  18. request = connection.request
  19. status, headers, body = call Rack::MockRequest.env_for(request.url, method: request.method, input: request.body)
  20. connection.respond status_symbol(status), headers, body.to_s
  21. end
  22. end
  23. end
  24.  
  25. def status_symbol(status)
  26. status.is_a?(Fixnum) ? Http::Response::STATUS_CODES[status].downcase.gsub(/\s|-/, '_').to_sym : status.to_sym
  27. end
  28.  
  29. def terminate
  30. @server.terminate
  31. end
  32. end
  33. end
  34.  
  35.  
  36. class MyApp
  37. include Reel::App
  38.  
  39. get "/foo" do |request|
  40. [200, {}, "hello foo"]
  41. end
  42.  
  43. end
  44.  
  45. MyApp.new("0.0.0.0", 3010)
  46.  
  47. # curl 127.0.0.1:3010/foo
Add Comment
Please, Sign In to add comment