LoginSignup
2
3

More than 5 years have passed since last update.

HerokuでDockerでTrusterdを動かすまで 準備編その2

Last updated at Posted at 2015-05-09

前回

Herokuの中で複数のポートを待ち受ける

これが出来ないと、nghttpxでHTTP/1.1で受けて、HTTP/2にして
trusterdに接続して、その結果を返すという一連の企みが出来ないことになる。

まずはSimpleHttpServerで複数Webサーバーを立ち上げ実験

server.rb
queue = %w[生 麦 生 米 生 卵]

server = SimpleHttpServer.new(
  server_ip:     "0.0.0.0",
  port:          ARGV[0] || 3000,
  document_root: "./",
)

server.location "/" do |r|
  content = ""
  content << `curl http://127.0.0.1:8000/`
  server.response_body = "#{content}\n"
  server.create_response
end

s2 = SimpleHttpServer.new(
  server_ip:     "127.0.0.1",
  port:          8000,
  document_root: "./",
)

s2.location "/" do |r|
  content = ""
  while rand > 0.1 do
    char = queue.shift
    content << char
    queue.push(char)
  end
  s2.response_body = "#{content}\n"
  s2.create_response
end

#server.run
pid1 = Process.fork() { server.run }
pid2 = Process.fork() { s2.run }
Process.waitpid pid1
Process.waitpid.pid2

うち向けのWebサーバーのs2に外向けのserverからcurlでアクセして結果を返せた。

参考記事

続き

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3