Tuesday, 1 May 2012

Deploying static website on Heroku.

Hi,

Some times we may have static page website with three to four html pages. We can use heroku for deploying static websites also.

Heroku uses Rack app for this.

Here are the steps that need to be taken for creating the static website in heroku.

Your folder should be organised like this:

- MyApp
  |- config.ru
  |- public
    |- index.html
    |- stylesheets
    |- images


In config.ru file add the following:

use Rack::Static,
  :urls => ["/stylesheets", "/images"],
  :root => "public"

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


And there you go, a static site being served on Heroku completely cached and easily served using a single dyno.

To know more information about this check the heroku website: https://devcenter.heroku.com/articles/static-sites-on-heroku

Thank You,
Uma Mahesh.

No comments:

Post a Comment