Skip to content

Instantly share code, notes, and snippets.

@ntulip
Created June 4, 2012 15:33
Show Gist options
  • Save ntulip/2869069 to your computer and use it in GitHub Desktop.
Save ntulip/2869069 to your computer and use it in GitHub Desktop.

Revisions

  1. ntulip created this gist Jun 4, 2012.
    25 changes: 25 additions & 0 deletions static.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    # From http://anti-pattern.com/2012/6/2/static-sites-on-heroku

    # Gemfile
    source "http://rubygems.org"

    gem "rack"

    # config.ru
    require "rubygems"
    require "bundler"
    Bundler.require(:default)

    map "/" do
    use Rack::Static, urls: ["/assets"], root: Dir.pwd

    run lambda { |env|
    headers = {
    "Content-Type" => "text/html",
    "Cache-Control" => "public, max-age=86400"
    }
    body = File.open("#{Dir.pwd}/index.html", File::RDONLY).read

    [200, headers, [body]]
    }
    end