cloud9上でsinatraを利用したい
まずはbundlerをインストールする
$ gem install bundler # 'Fetching: bundler-1.16.1.gem (100%)' # 'Successfully installed bundler-1.16.1' # '1 gem installed'
bundlerを初期化する(Gemfileが生成される)
$ bundle init # 'Writing new Gemfile to /home/ubuntu/workspace/Gemfile'
Gem fileを編集
# frozen_string_literal: true source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } gem 'sinatra'
gemをインストールする
$ bundle install --path vendor/bundle # Fetching gem metadata from https://rubygems.org/.......... # Resolving dependencies... # Using bundler 1.16.1 # Fetching mustermann 1.0.1 # Installing mustermann 1.0.1 # Fetching rack 2.0.3 # Installing rack 2.0.3 # Fetching rack-protection 2.0.0 # Installing rack-protection 2.0.0 # Fetching tilt 2.0.8 # Installing tilt 2.0.8 # Fetching sinatra 2.0.0 # Installing sinatra 2.0.0 # Bundle complete! 1 Gemfile dependency, 6 gems now installed. # Bundled gems are installed into `./vendor/bundle`
ファイルを作成する
touch app.rb
ファイルの中身を編集
require 'sinatra' get '/' do 'hello' end
最後にポート番号とIPを指定して起動する **※重要**
(cloud9側でデフォルトで指定している環境変数なので、中身を知りたい場合は `$ echo $IP` とか `$ echo $PORT`とか実行すると見れる)
bundle exec ruby app.rb -p $PORT -o $IP # [2018-01-22 04:40:20] INFO WEBrick 1.3.1 # [2018-01-22 04:40:20] INFO ruby 2.4.0 (2016-12-24) [x86_64-linux] # ~中略~ # [2018-01-22 04:41:13] INFO going to shutdown ... # [2018-01-22 04:41:13] INFO WEBrick::HTTPServer#start done.