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

时间:2012-05-11 12:23:17

标签: 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

10 个答案:

答案 0 :(得分:203)

一种简单的方法是将HTML应用程序伪装成PHP应用程序。 Heroku正确识别PHP应用程序。

  1. 将index.html文件重命名为home.html。
  2. 创建一个index.php文件并包含您的条目html文件。如果您的HTML条目文件按照建议命名为home.html,则index.php应如下所示:

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

  3. 在您要推送的计算机的命令行中,键入:

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

  4. Heroku现在可以正确检测您的应用程序作为php应用程序:

    -----> 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感谢lemiffe的博客文章:http://www.lemiffe.com/how-to-deploy-a-static-page-to-heroku-the-easy-way/

答案 1 :(得分:38)

这是一个更优雅的方法:只需添加一个名为package.json的文件,告诉Heroku使用harp作为您的服务器:

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

然后部署到Heroku。完成!

更多信息:https://harpjs.com/docs/deployment/heroku

答案 2 :(得分:12)

您可以使用机架执行此操作:

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

或者你可以使用像Octopress / Jekyll这样使用sinatra的东西。

但是你需要一个最小的堆栈来提供html静态内容

答案 3 :(得分:11)

这对我有用:

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

如果输入点为main.html,请使用以下一行内容创建index.php

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

然后执行以下步骤:

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

转到http://myApp.herokuapp.com/,您的应用现在应该在线。

答案 4 :(得分:3)

如果有人发现上述答案难以理解,那么这是一种非常简单的方法。

你的静态网站的根目录是index.html(比如说​​),现在你想把它合成到Heroku,怎么样?

git init初始化一个git repo

git add -A添加文件

git commit -m "init commit"提交文件

现在在根目录中添加两个文件composer.jsonindex.php as,

touch composer.json

touch index.php

然后将此行添加到index.php

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

然后将{}添加到composer.json

现在只需运行git push heroku master即可完成!

答案 5 :(得分:2)

我知道这可能有点旧了但是我最终使用Vienna Gemw来部署它,基本上它是一个小的Rack应用程序,它可以让你只需一个公共文件夹(css,images,js,html)中的所有内容几行Ruby:

require 'vienna'
run Vienna

此外,要在heroku上部署它,您需要创建一个Gemfile:

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

然后运行bundle install,以防你没有安装bundle gem,只需在你的终端上运行:

sudo gem install bundle

就是这些,你可以获得更多信息:http://kmikael.com/2013/05/28/creating-static-sites-in-ruby-with-rack/

答案 6 :(得分:1)

按照此步骤

第1步

键入touch composer.json index.php index.html

第2步 在index.php中输入:

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

,在composer.json中,键入{}

第3步

git add .

git commit -m "[your message]"

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

答案 7 :(得分:0)

嗯... heroku拒绝应用程序的一个原因可能是它试图检测rails 3.1.x应用程序中的资产管道。

为什么不通过运行

在默认堆栈 Bamboo 上创建您的应用程序
heroku create

然后,所有js和css都可以进入rails app中的公共文件夹,并且资产管道已停用。

答案 8 :(得分:0)

嗯,每当您的网页包含HTML,CSS和JavaScript时,请按照以下两个步骤操作:

1)将一个文件命名为index.html(保留其中的evreything)ex:script,stylesheet&amp;体。

2)现在,更改这些文件,复制并粘贴这些相同的文件,但将域名更改为index.php

然后部署在Heroku上。

因此,此方法将帮助您部署Web页面

答案 9 :(得分:0)

2020更新:

如果您获得的空白页面包含此处提到的PHP答案,请尝试以下操作- 如果您的主页位于index.html上:

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

创建Git存储库并在添加文件后提交:

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

Heroku部署-

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