10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SinatraをThinで起動したときのメモ

Last updated at Posted at 2015-11-14

Thinという速いWebサーバがあるらしいのでSinatraと一緒に使ってみた

ソースファイル

Gemfile
source "https://rubygems.org"

gem 'sinatra'
gem 'shotgun'
gem 'thin'

gem 'config'

group :test do
  gem 'rspec'
end
main.rb
require 'rubygems'
require 'sinatra'

get '/' do
  body "Hello world"
end

get '/user' do
  body "User World"
end

ソースファイルはこれだけ

設定ファイル

ふだんRailsを使っていると自動で生成してくれるのであんまし気にしないけどSinatraのときはconfig.ruを手で書く

config.ru
require 'rubygems'
require 'sinatra'

require './main.rb'
run Sinatra::Application

Procfileには以下を追記してthinが起動するようにする。

Bash
web: bundle exec thin -R config.ru -p $PORT -e $RACK_ENV start

ローカルでの起動

Bash
$ bundle exec thin -p 8000 start

Railsのときの同じようにlog/, puclic/, tmp/, tmp/pids/を作っておく必要があるらしい。

Shotgunをつかう場合はこのコマンドを実行

Bash
$ bundle exec shotgun main.rb -p 8000

使った資料たち

10
11
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
10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?