Created
October 17, 2018 13:15
-
-
Save jgaskins/002143f3fc128d38ab7eaa73eef7f789 to your computer and use it in GitHub Desktop.
Forking HTTP server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PrintPid | |
include HTTP::Handler | |
def call(context) | |
context.response.puts Process.pid | |
end | |
end | |
workers = Array.new(8) do |i| | |
process = fork do | |
server = HTTP::Server.new([ | |
HTTP::ErrorHandler.new, | |
HTTP::LogHandler.new, | |
HTTP::CompressHandler.new, | |
HTTP::StaticFileHandler.new("./public"), | |
PrintPid.new, | |
]) | |
server.bind_tcp host: "0.0.0.0", port: 9393, reuse_port: true | |
server.listen | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment