├── public ├── js │ └── foo.js ├── css │ └── bar.css ├── images │ └── dodgeball.jpg └── index.html ├── Gemfile ├── Gemfile.lock ├── config.ru └── README.md /public/js/foo.js: -------------------------------------------------------------------------------- 1 | alert('ಠ_ಠ'); -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rack' 4 | -------------------------------------------------------------------------------- /public/css/bar.css: -------------------------------------------------------------------------------- 1 | p { 2 | width: 365px; 3 | padding: 5px 5px 5px 5px; 4 | border: 1px solid #990000; 5 | } -------------------------------------------------------------------------------- /public/images/dodgeball.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leereilly/static-site-heroku-cedar-example/HEAD/public/images/dodgeball.jpg -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: http://rubygems.org/ 3 | specs: 4 | rack (1.4.1) 5 | 6 | PLATFORMS 7 | ruby 8 | 9 | DEPENDENCIES 10 | rack 11 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | use Rack::Static, 2 | :urls => ["/images", "/js", "/css"], 3 | :root => "public" 4 | 5 | run lambda { |env| 6 | [ 7 | 200, 8 | { 9 | 'Content-Type' => 'text/html', 10 | 'Cache-Control' => 'public, max-age=86400' 11 | }, 12 | File.open('public/index.html', File::RDONLY) 13 | ] 14 | } -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |Read the gist; explore the repo.
12 |
13 |
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This article was forked from [Marshall Huss's Bamboo stack article](https://devcenter.heroku.com/articles/static-sites-on-heroku) and updated by [Lee Reilly](http://www.leereilly.net). Lee is a toolsmith and master pintsman hacking on [GitHub Enterprise](https://enterprise.github.com).
2 |
3 | # Static Sites with Ruby on Heroku/Cedar
4 |
5 | Sometimes you just have a static website with one or two pages. Here is a simple way to host your static site and cache it on Heroku using a [Rack](http://rack.rubyforge.org/) app.
6 |
7 | Your folder should be organized like this:
8 |
9 | ```
10 | - MySite
11 | |- config.ru
12 | |- Gemfile
13 | |- public
14 | |- index.html
15 | |- images
16 | |- js
17 | |- css
18 | ```
19 |
20 | In `Gemfile` file add the following:
21 |
22 | ```ruby
23 | source :rubygems
24 |
25 | gem 'rack'
26 | ```
27 |
28 | You should use [bundler](https://devcenter.heroku.com/articles/bundler) to generate the `Gemfile.lock` file:
29 |
30 | ```
31 | GEM
32 | remote: http://rubygems.org/
33 | specs:
34 | rack (1.4.1)
35 |
36 | PLATFORMS
37 | ruby
38 |
39 | DEPENDENCIES
40 | rack
41 | ```
42 |
43 | In `config.ru` file add the following:
44 |
45 | ```ruby
46 | use Rack::Static,
47 | :urls => ["/images", "/js", "/css"],
48 | :root => "public"
49 |
50 | run lambda { |env|
51 | [
52 | 200,
53 | {
54 | 'Content-Type' => 'text/html',
55 | 'Cache-Control' => 'public, max-age=86400'
56 | },
57 | File.open('public/index.html', File::RDONLY)
58 | ]
59 | }
60 | ```
61 |
62 | This assumes that your template uses relative references to the images and stylesheets. Go ahead and deploy the app. If you are not sure how to deploy to Heroku check out the [quickstart guide](https://devcenter.heroku.com/articles/quickstart).
63 |
64 | And there you go, a static site being served on Heroku completely cached and easily served using a single [dyno](https://devcenter.heroku.com/articles/dynos).
65 |
66 | If this article is incorrect or outdated, or omits critical information, please [let us know](https://devcenter.heroku.com/articles/static-sites-on-heroku#). For all other issues, please see our [support channels](https://devcenter.heroku.com/articles/support-channels).
--------------------------------------------------------------------------------