是否可以上传一个简单的 html 和 javascript 文件结构到 heroku?

我正在尝试将我的一个开源项目部署到 heroku,它必然非常简单,只有静态 html 和 javascript。但是它们不支持静态站点吗?如果我不打算使用除了 html 和 javascript 之外的任何东西,我宁愿不把它变成一个 Sinatra 项目。

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




~/sites/d4-site $ git remote -v
heroku  git@heroku.com:quiet-ice-4769.git (fetch)
heroku  git@heroku.com: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
57969 次浏览

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

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.

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/

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/

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.

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

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!

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

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']

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