3
3

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.

Static Site on Heroku

3
Posted at

Herokuで静的なWebページを公開する方法です。
HerokuってApplicationServerのPaasなんで、通常、アプリケーションのルートにindex.htmlをおいてあげたとしてもクライアントから直接Getすることはできません。

なんでRubyでサーブレットを書いて(Rubyでもサーブレットっていうのかわからないのですが)公開する方法がStatic Sites with Ruby on Heroku/Bambooに記載されています。

実際にやってみました。

sample
	|-config.ru
	|
	|-public
		|-index.html
		|-lib
			|-sample.js

use Rack::Static に登録されていないディレクトリの静的ファイルにアクセスしようとするとエラーが発生すると思います。
私の試した限りですが、「lib」を登録せずに実行した場合、sample.jsの先頭でエラーが発生し、読み込まれません。

config.ru
use Rack::Static, 
  :urls => ["/lib"], 
  :root => "public"

run lambda { |env|
  [
    200, 
    {
      'Content-Type'  => 'text/html', 
      'Cache-Control' => 'public, max-age=86400' 
    },
    File.open('public/index.html', File::RDONLY)
  ]
}

今回は、Rubyをアプリケーションとして使用しますので、cedarスタックではなく、Bambooスタックを使用してください。cedarスタックではRubyは動作しません。

//アプリケーションを作成する際はBanbooスタックに作成してください。
$heroku create sampleApp

後は、普通通り、アプリケーションのgitリポジトリにgit pushしてあげるだけです。

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?