mruby-simplehttpserver is a HTTP Server with less dependency for mruby. mruby-simplehttpserver depends on mruby-io, mruby-socket and mruby-http. A Web server using mruby-simplehttpserver run on a environment which is not very rich like OSv or simple Linux box.
MRuby::Build.new do |conf|
# ... (snip) ...
conf.gem :github => 'iij/mruby-io'
conf.gem :github => 'iij/mruby-pack'
conf.gem :github => 'iij/mruby-socket'
conf.gem :github => 'mattn/mruby-http'
conf.gem :github => 'matsumoto-r/mruby-simplehttpserver'
end
./bin/mruby server.rb
under the MIT License:
- see LICENSE file
If you see more example, see example/server.rb
#
# Server Configration
#
server = SimpleHttpServer.new({
:server_ip => "0.0.0.0",
:port => 8000,
:document_root => "./",
})
#
# HTTP Initialize Configuration Per Request
#
# You can use request parameters at http or location configration
# r.method
# r.schema
# r.host
# r.port
# r.path
# r.query
# r.headers
# r.body
server.http do |r|
server.set_response_headers({
"Server" => "my-mruby-simplehttpserver",
"Date" => server.http_date,
})
end
#
# Location Configration
#
# /mruby location config
server.location "/mruby" do |r|
if r.method == "POST"
server.response_body = "Hello mruby World. Your post is '#{r.body}'\n"
else
server.response_body = "Hello mruby World at '#{r.path}'\n"
end
server.create_response
end
server.run