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

Jer*_*ith 80 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
Run Code Online (Sandbox Code Playgroud)

pka*_*ane 206

一种简单的方法是将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

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
...
Run Code Online (Sandbox Code Playgroud)

Mad感谢lemiffe的博客文章:http://www.lemiffe.com/how-to-deploy-a-static-page-to-heroku-the-easy-way/

  • 这样做更简单,应该被接受为正确的答案 (27认同)
  • 为了使它更简单,您可以将index.html重命名为index.php (5认同)
  • 注意:我需要先添加composer.json才能使其正常工作.https://devcenter.heroku.com/articles/getting-started-with-php#a-hello-world-application (3认同)
  • 这太棒了! (2认同)

Har*_*ood 38

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

{
  "name": "my-static-site",
  "version": "1.0.0",
  "description": "This will load any static html site",
  "scripts": {
    "start": "harp server --port $PORT"
  },
  "dependencies": {
    "harp": "*"
  }
}
Run Code Online (Sandbox Code Playgroud)

然后部署到Heroku.完成!

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

  • 在所有答案中,这是截至2016年11月的工作答案 (3认同)
  • 是的,这个快速而简单 (2认同)
  • 像魅力一样工作.万分感谢 (2认同)
  • 2017/8/1,可以确认这项工作. (2认同)

Tia*_*nyj 13

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

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

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

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

  • 再读一遍我的句子. (21认同)
  • OP没有要求Ruby解决方案. (16认同)

qed*_*qed 11

这对我有用:

cd myProject 
git init
heroku create myApp 
heroku git:remote -a myApp 
Run Code Online (Sandbox Code Playgroud)

如果是入口点main.html,则index.php使用以下单行内容创建:

<?php include_once("main.html"); ?>
Run Code Online (Sandbox Code Playgroud)

然后执行以下步骤:

echo '{}' > composer.json 
git add . 
git commit -am "first commit" 
git push heroku master
Run Code Online (Sandbox Code Playgroud)

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


Scr*_*tch 5

有一种非常简单的方法可以做到,以防万一有人发现上述答案难以理解。

您的静态网站的根目录为index.html(例如),现在您想将其部署到 Heroku,如何?

git init # initialise a git repo

git add -A # add the files

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

# Now add two files in the root, composer.json and index.php like so - 
touch composer.json
touch index.php

# Then add this line to index.php, making a PHP app and just asking it to display index.html - 
<?php include_once("index.html"); ?>

# Now open composer.json and add an empty object - 
{}
Run Code Online (Sandbox Code Playgroud)

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