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应用程序.
创建一个index.php文件并包含您的条目html文件.如果您的HTML条目文件按照建议命名为home.html,则index.php应如下所示:
<?php include_once("home.html"); ?>
在您要推送的计算机的命令行中,键入:
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/
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
Tia*_*nyj 13
您可以使用机架执行此操作:
https://devcenter.heroku.com/articles/static-sites-on-heroku
或者你可以使用像Octopress/Jekyll这样使用sinatra的东西.
但是你需要一个最小的堆栈来提供html静态内容
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/,您的应用现在应该在线.
有一种非常简单的方法可以做到,以防万一有人发现上述答案难以理解。
您的静态网站的根目录为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
完成!