Sha256: 782d6b2b387d4100a7725d4d89deef76c991b2b1d13d934fe4e43c386fb68945

Contents?: true

Size: 1.38 KB

Versions: 423

Compression:

Stored size: 1.38 KB

Contents

#!/usr/bin/env ruby
# encoding: utf-8

require 'webrick'
include WEBrick
$:.unshift 'ext'
$:.unshift 'lib'
require 'json'

class JSONServlet < HTTPServlet::AbstractServlet
  @@count = 1

  def do_GET(req, res)
    obj = {
      "TIME" => Time.now.strftime("%FT%T"),
      "foo" => "Bär",
      "bar" => "© ≠ €!",
      'a' => 2,
      'b' => 3.141,
      'COUNT' => @@count += 1,
      'c' => 'c',
      'd' => [ 1, "b", 3.14 ],
      'e' => { 'foo' => 'bar' },
      'g' => "松本行弘",
      'h' => 1000.0,
      'i' => 0.001,
      'j' => "\xf0\xa0\x80\x81",
    }
    res.body = JSON.generate obj
    res['Content-Type'] = "application/json"
  end
end

def create_server(err, dir, port)
  dir = File.expand_path(dir)
  err.puts "Surf to:", "http://#{Socket.gethostname}:#{port}"

  s = HTTPServer.new(
    :Port         => port,
    :DocumentRoot => dir,
    :Logger       => WEBrick::Log.new(err),
    :AccessLog    => [
      [ err, WEBrick::AccessLog::COMMON_LOG_FORMAT  ],
      [ err, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
      [ err, WEBrick::AccessLog::AGENT_LOG_FORMAT   ]
    ]
  )
  s.mount("/json", JSONServlet)
  s
end

default_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'data'))
dir = ARGV.shift || default_dir
port = (ARGV.shift || 6666).to_i
s = create_server(STDERR, dir, 6666)
t = Thread.new { s.start }
trap(:INT) do
  s.shutdown
  t.join
  exit
end
sleep

Version data entries

423 entries across 370 versions & 64 rubygems

Version Path
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/json-2.2.0/tools/server.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/json-2.3.0/tools/server.rb
cloudsmith-api-0.49.118 vendor/bundle/ruby/2.6.0/gems/json-2.3.0/tools/server.rb
cloudsmith-api-0.49.98 vendor/bundle/ruby/2.6.0/gems/json-2.3.0/tools/server.rb
cloudsmith-api-0.49.94 vendor/bundle/ruby/2.6.0/gems/json-2.3.0/tools/server.rb
json_pure-2.3.0 tools/server.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/json-2.2.0/tools/server.rb
cloudsmith-api-0.49.21 vendor/bundle/ruby/2.6.0/gems/json-2.3.0/tools/server.rb
cloudsmith-api-0.49.15 vendor/bundle/ruby/2.6.0/gems/json-2.3.0/tools/server.rb
cloudsmith-api-0.49.13 vendor/bundle/ruby/2.6.0/gems/json-2.3.0/tools/server.rb
cloudsmith-api-0.49.9 vendor/bundle/ruby/2.3.0/gems/json-2.3.0/tools/server.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/json-2.3.0/tools/server.rb
json-2.3.0 tools/server.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/json-2.2.0/tools/server.rb
tdiary-5.1.0 vendor/bundle/gems/json-2.2.0/tools/server.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/json-2.2.0/tools/server.rb
scout-5.9.13 vendor/json_pure/tools/server.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/json-2.2.0/tools/server.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/json-2.2.0/tools/server.rb
cloudsmith-api-0.44.4 vendor/bundle/ruby/2.3.0/gems/json-2.2.0/tools/server.rb