是否可以将简单的 html 和 javascript 文件结构上传到 heroku
Is it possible to upload a simple html and javascript file structure to heroku?
我正在尝试将我的一个开源项目部署到heroku,它必然非常简单,只需静态html和javascript。 但是它们不支持静态站点吗? 我宁愿不把它变成一个Sinatra项目,如果我不打算使用html和javascript之外的任何东西。
~/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
一个简单的方法是将HTML应用程序伪装成PHP应用程序。Heroku 可以正确识别 PHP 应用程序。
- 将索引.html文件重命名为 home.html。
-
创建一个索引.php文件并包含您的入口 html 文件。如果按照建议.html将 HTML 条目文件命名为 home,则索引.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
...
疯狂 感谢 lemiffe 的博客文章:http://www.lemiffe.com/how-to-deploy-a-static-page-to-heroku-the-easy-way/
这是一个更优雅的方法: 只需添加一个名为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": "*"
}
}
然后部署到希罗库。 做!
更多信息:https://harpjs.com/docs/deployment/heroku
您可以使用机架来执行此操作:
https://devcenter.heroku.com/articles/static-sites-on-heroku
或者你可以使用像Octopress/Jekyll这样使用sinatra的东西。
但是你需要一个最小的堆栈来提供html静态内容
以下是对我有用的方法:
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/,你的应用现在应该已联机。
有一种更简单的方法可以做到这一点,以防万一有人发现其他答案难以理解。
假设您的静态网站根目录为 index.html
.现在你想把它部署到Heroku,怎么做?
# 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
{}
现在只需运行git push heroku master
即可完成!
这可能有点旧,但我最终使用 Vienna Gemw 来部署它,基本上它是一个小型的 Rack 应用程序,只需几行 Ruby,即可为您提供公共文件夹中的所有内容(css、images、js、html):
require 'vienna'
run Vienna
此外,要在 heroku 上部署它,您需要创建一个 Gemfile:
source 'https://rubygems.org'
gem 'rack'
gem 'vienna'
然后运行捆绑包安装,如果您没有安装捆绑 gem,只需在终端上运行:
sudo gem install bundle
仅此而已,您可以获得有关以下内容的更多信息: http://kmikael.com/2013/05/28/creating-static-sites-in-ruby-with-rack/
按照以下步骤操作
步骤 1
类型 touch composer.json index.php index.html
步骤 2在索引中.php键入:
<?php include_once("index.html"); ?>
并在 composer.json 中键入 {}
步骤 3
git add .
git commit -m "[your message]"
git push ['yourrepo'] ['yourbranch']
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 login
heroku apps:create my-static-site-example
git push heroku master
嗯......Heroku拒绝该应用程序的一个原因可能是它试图在Rails 3.1.x应用程序中检测资产管道。
为什么不在默认堆栈 Bamboo 上创建您的应用程序,只需运行
heroku create
然后,您的所有 js 和 css 都可以进入 rails 应用程序中的公共文件夹,并停用资产管道。
好吧,只要你的网页包含HTML,CSS和JavaScript,所以只需遵循2个步骤:
1)使一个文件命名为索引.html(保留evreything)ex:script,stylesheet和body。
2)现在,更改这些文件,复制并粘贴这些相同的文件,但将域更改为索引.php
然后部署在 Heroku 上。
因此,此方法将帮助您部署网页
- 文件结构:使用索引.js文件级联访问子模块或子文件
- 当客户端是服务器时,使用 client-JS 读取文件结构
- PowerPoint文件结构
- 淘汰js应用程序的正确文件结构是什么
- Bower安装的相同软件包文件结构不同
- MEAN堆栈文件结构&咕哝
- 编译项目中的所有 TypeScript 文件并维护文件结构
- Javascript:列出文件和文件夹结构
- 是否可以将简单的 html 和 javascript 文件结构上传到 heroku
- 节点 - Express + Ember + Socket io项目文件结构,用于MVC开发
- 导入iPython自定义小部件函数(文件结构?)
- 文件结构首选项
- 角度文件结构
- ExtJs 4+Zend(文件结构)-Ext.Loader问题
- AngularJS应用程序文件结构
- 使用javascript将Sharepoint在线文件结构转换为json文件
- 文件结构的最佳实践-使用请求模块(Node.js + Express.js)
- 电子桌面应用程序文件结构
- Javascript文件结构-任何好的解决方案
- 我如何使一个网站从文件结构自动显示文件