简体   繁体   中英

How to create rack application to be used by Rails?

Rails itself is based around multiple independent processes that are stateless inbetween requests. I need to add a stateful centralized service (a game automatcher) to my Rails app.

From what little I know I should make that stateful service a rack application. Is there some tutorial out there on how to make a rack application and also importantly how to communicate with it from Rails. What is the idiomatic way to deploy it with Rails and the idiomatic place to put it in my git Rails codebase?

I got my question answered in another question:

How to read POST data in rack request

require 'json'

class Greeter
  def call(env)
    req = Rack::Request.new(env)
    if req.post?
      puts req.POST()
    end
    [200, {"Content-Type" => "application/json"}, [{x:"Hello World!"}.to_json]]
  end
end

run Greeter.new

and use JSON.parse( req.body.read ) to parse POST data.

除了机架以外,另一个选择是守护您的应用程序。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM