-
Notifications
You must be signed in to change notification settings - Fork 28
StarteKit
Michael edited this page Jul 3, 2016
·
6 revisions
Welcome to the mruby-cli wiki!
mruby-simplehttpserver example
gem install mgem
mruby-cli --setup mruby_app
cd mruby_app
mgem update
mgem list
for i in `echo "mruby-io mruby-pack mruby-socket mruby-http mruby-simplehttpserver"`; do mgem add $i; done
mgem list active
mgem config default
# merge build_config.rb
My example
# build_config.rb
def gem_config(conf)
# user-defined GEMs
conf.gem :git => 'https://github.com/gromnitsky/mruby-dir-glob.git'
conf.gem :git => 'https://github.com/iij/mruby-dir.git'
conf.gem :git => 'https://github.com/mattn/mruby-http.git'
conf.gem :git => 'https://github.com/iij/mruby-io.git'
conf.gem :git => 'https://github.com/iij/mruby-pack.git'
conf.gem :git => 'https://github.com/iij/mruby-socket.git'
conf.gem :git => 'https://github.com/matsumoto-r/mruby-simplehttpserver.git'
# be sure to include this gem (the cli app)
conf.gem File.expand_path(File.dirname(__FILE__))
end
MRuby::Build.new do |conf|
toolchain :clang
gem_config(conf)
end
MRuby::CrossBuild.new('x86_64-apple-darwin14') do |conf|
toolchain :clang
[conf.cc, conf.linker].each do |cc|
cc.command = 'x86_64-apple-darwin14-clang'
end
conf.cxx.command = 'x86_64-apple-darwin14-clang++'
conf.archiver.command = 'x86_64-apple-darwin14-ar'
conf.build_target = 'x86_64-pc-linux-gnu'
conf.host_target = 'x86_64-apple-darwin14'
gem_config(conf)
end
Load your code
# mruby_app/mrblib/mruby_app.rb
def __main__(argv)
if argv[1] == "version"
puts "v#{MrubyApp::VERSION}"
else
puts "server.run at http://127.0.0.1:8001"
server = SimpleHttpServer.new({
:server_ip => "0.0.0.0",
:port => 8001,
:document_root => "./",
:debug => false,
})
server.http do |r|
server.set_response_headers({
"Server" => "my-mruby-simplehttpserver",
"Date" => server.http_date,
})
end
server.location "/" do |r|
server.set_response_headers "Content-type" => "text/html; charset=utf-8"
server.response_body = "<h1>root path.</h1>\n"
server.create_response
end
server.run
end
end
docker-machine start default
docker-machine env
docker-compose build
docker-compose run compile
docker-compose run shell
docker-compose run mtest
docker-compose run bintest
docker-compose run release
docker-compose run package
after docker-compose build
I did it
mruby_app/mruby/build/x86_64-apple-darwin14/bin/mruby_app
# mruby_app fail on first request and I dont known why at this moment
# try this
mruby_app/mruby/build/x86_64-apple-darwin14/bin/mruby mruby_app/mrblib/mruby_app.rb
# another console
cryload -s http://localhost:8000 -n 10000
Preparing to make it CRY for 10000 requests!
Total request made: 1000
Total request made: 2000
Total request made: 3000
Total request made: 4000
Total request made: 5000
Total request made: 6000
Total request made: 7000
Total request made: 8000
Total request made: 9000
Completed All Requeasts!
-------------------------------
Time taken per request:
Min: 0.654 ms
Max: 3508.4 ms
Average: 8.09 ms
Requests Statistics:
Request p/s: 123.603
2xx requests 10000
Non 2xx requests 0
Total request made: 10000
Total time taken: 80.9043 seconds
I just leave it here like cheat sheet