Is it possible to upload a simple html and javascript file structure to heroku?

JavascriptHeroku

Javascript Problem Overview


I'm trying to deploy an open source project of mine to heroku, it is by necessity very simple with just static html and javascript. But do they not support static sites? I'd rather not make it a Sinatra project if I don't plan on ever using anything but html and javascript.

~/sites/d4-site $ heroku create --stack cedar
Creating quiet-ice-4769... done, stack is cedar
http://quiet-ice-4769.herokuapp.com/ | [email protected]:quiet-ice-4769.git
Git remote heroku added

   
~/sites/d4-site $ git remote -v
heroku	[email protected]:quiet-ice-4769.git (fetch)
heroku	[email protected]:quiet-ice-4769.git (push)

   
~/sites/d4-site $ git push heroku master
Counting objects: 53, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (49/49), done.
Writing objects: 100% (53/53), 206.08 KiB, done.
Total 53 (delta 4), reused 0 (delta 0)

-----> Heroku receiving push
-----> Removing .DS_Store files
 !     Heroku push rejected, no Cedar-supported app detected

Javascript Solutions


Solution 1 - Javascript

A simple way is to masquerade the HTML app as a PHP App. Heroku properly identifies PHP apps.

  1. Rename your index.html file to home.html.

  2. Create an index.php file and include your entry html file. If your HTML entry file is named home.html as recommended, your index.php should look like:

    <?php include_once("home.html"); ?>

  3. In your command line on the machine you are pushing from, type:

git add . git commit -m 'your commit message' git push heroku master

Heroku should properly detect your app now as a php app:

-----> PHP app detected
-----> Bundling Apache version 2.2.22
-----> Bundling PHP version 5.3.10
-----> Discovering process types
       Procfile declares types -> (none)
       Default types for PHP   -> web

-----> Compiled slug size: 9.9MB
-----> Launching... done, v3
...

Mad Thanks to lemiffe for his blog post: http://www.lemiffe.com/how-to-deploy-a-static-page-to-heroku-the-easy-way/

Solution 2 - Javascript

Here is a more elegant method: Just add a file called package.json which tells Heroku to use harp as your server:

{
  "name": "my-static-site",
  "version": "1.0.0",
  "description": "This will load any static html site",
  "scripts": {
    "start": "harp server --port $PORT"
  },
  "dependencies": {
    "harp": "*"
  }
}

and then deploy to Heroku. Done!

Further information: https://harpjs.com/docs/deployment/heroku

Solution 3 - Javascript

You can use rack to do this:

https://devcenter.heroku.com/articles/static-sites-on-heroku

or you can use something like Octopress/Jekyll who uses sinatra.

But you need a minimum stack to serve html static content

Solution 4 - Javascript

Here is what worked for me:

cd myProject 
git init
heroku create myApp 
heroku git:remote -a myApp 

If the entry point is main.html, create index.php with this single line of content:

<?php include_once("main.html"); ?>

and then perform the following steps:

echo '{}' > composer.json 
git add . 
git commit -am "first commit" 
git push heroku master

Go to http://myApp.herokuapp.com/ and your app should be online now.

Solution 5 - Javascript

There's a much easier way to do it just in case anyone finds the other answers hard to follow.

Say you have your static website with the root at index.html. Now you want to deploy it to Heroku, how?

# initialise a git repo
git init

# add the files
git add -A

# commit the files
git commit -m "init commit"

# Now add two files at the root, composer.json and index.php
touch composer.json
touch index.php

# add this line to index.php, making a PHP app that simply displays index.html
<?php include_once("index.html"); ?>

# add an empty object to composer.json
{}

Now simply run git push heroku master and you're done!

Solution 6 - Javascript

I know this might be a little old but I ended up using Vienna Gemw to deploy this, basically its a small Rack application that will let you serve everything in your public folder (css, images, js, html) with just a couple of lines of Ruby:

require 'vienna'
run Vienna

Also, for deploying this on heroku you need to create a Gemfile:

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

Then run bundle install, in case you don't have the bundle gem installed just run on your terminal:

sudo gem install bundle

And thats pretty much of it, you can have more information on: http://kmikael.com/2013/05/28/creating-static-sites-in-ruby-with-rack/

Solution 7 - Javascript

Follow this steps

Step 1

Type touch composer.json index.php index.html

Step 2 in the index.php type:

<?php include_once("index.html"); ?>

and in the composer.json type {}

Step 3

git add .

git commit -m "[your message]"

git push ['yourrepo'] ['yourbranch']

Solution 8 - Javascript

2020 Update:

If you get a blank page with the PHP answer mentioned here, try this - If your homepage is at index.html :

echo '<?php header( 'Location: /index.html' ) ;  ?>' > index.php
echo '{}' > composer.json

Creating a Git repo and committing after adding files :

git init
git add .
git commit -m "My site ready for deployment."

Heroku deployment -

heroku login
heroku apps:create my-static-site-example
git push heroku master

Solution 9 - Javascript

Hmmm... one reason that heroku is rejecting the app could be that it is trying to detect asset pipeline in rails 3.1.x apps i think.

Why not create your app on the default stack Bamboo by running just

heroku create

Then all your js and css can go into public folder in rails app with asset pipeline deactivated.

Solution 10 - Javascript

Well , whenever your Web-page's contain HTML, CSS and JavaScript , so follow just 2 steps :

  1. Make one file give name as index.html (keep evreything in it) ex:script,stylesheet & body.

  2. Now, change these file, copy and paste these same file but change domain to index.php

Then deploy on a Heroku.

Hence this method will help you to deploy your Web-Pages

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJeremy SmithView Question on Stackoverflow
Solution 1 - JavascriptpkananeView Answer on Stackoverflow
Solution 2 - JavascriptHarlan T WoodView Answer on Stackoverflow
Solution 3 - JavascriptTiago PeczenyjView Answer on Stackoverflow
Solution 4 - JavascriptqedView Answer on Stackoverflow
Solution 5 - JavascriptScrotchView Answer on Stackoverflow
Solution 6 - JavascriptRonier LopezView Answer on Stackoverflow
Solution 7 - Javascriptuser4920718View Answer on Stackoverflow
Solution 8 - JavascriptAditya BansalView Answer on Stackoverflow
Solution 9 - JavascriptHishalvView Answer on Stackoverflow
Solution 10 - JavascriptAamir M MemanView Answer on Stackoverflow