Question

I'm attempting to upload a simple one page web page using Heroku.

I was previously using the Play! Framework but it seems overkill for a single page with some javascript.

+ project/
 + public/
  + css/
   ...
  + img/
   ...
  + js/
   ...
 index.html

How do I upload a basic set of static files to Heroku? There seems to be no documentation on their website on how to do this.

Was it helpful?

Solution

It is not the purpose of Heroku to host static websites. However, you still can do it but you have to create either a Ruby on Rails, Play, etc. project, add the HTML in the folders.

OTHER TIPS

Heroku doesn't really support static web pages, it supports Apps. However, a static web page can trivially be 'enhanced' to be a PHP application by adding a dummy index.php.

So if you want to host a file foo.html as a Heroku app Foo, then: 1. Create Foo on Heroku. 2. [Clone empty repository to local directory] git clone git@heroku.com:Foo.git -o heroku 3. touch index.php 4. [add foo.html] 5. git add . 6. git commit -m 'test' 7. git push heroku master

Heroku has a guide to doing this with Rack: https://devcenter.heroku.com/articles/static-sites-ruby

Basically, create a simple Rack app with a config.ru file:

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

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

a Gemfile:

source "https://rubygems.org"
gem 'rack'

and a public folder with an index.html file and folders for other assets, structured like this:

my_site/config.ru
my_site/Gemfile
my_site/public/index.html
my_site/public/css
my_site/public/images
my_site/public/js

And someone has made a site that will generate all the necessary files for you: http://herokustaticmagico.herokuapp.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top