Sha256: 347c258eba7961d87378fae92acd765456ef4119a7d6baacb30606d00cefeb52

Contents?: true

Size: 837 Bytes

Versions: 2

Compression:

Stored size: 837 Bytes

Contents

#!/usr/bin/env rackup --port 8081
# encoding: utf-8

# http://groups.google.com/group/json-rpc/web/json-rpc-over-http

$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)

require "rpc"
require "rack/request"

require_relative "helpers"

RPC.logging = true
# RPC.development = true

class RpcRunner
  def server
    @server ||= RPC::Server.new(RemoteObject.new)
  end

  def call(env)
    request = Rack::Request.new(env)
    command = request.body.read
    binary  = self.server.execute(command)
    if binary.match(/NoMethodError/)
      response(404, binary)
    else
      response(200, binary)
    end
  end

  def response(status, body)
    headers = {
      "Content-Type" => "application/json-rpc",
      "Content-Length" => body.bytesize.to_s}
    [status, headers, [body]]
  end
end

map("/") do
  run RpcRunner.new
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sync_service-0.1.0 lib/rpc/examples/server.ru
sync_service-0.0.8 lib/rpc/examples/server.ru