是否可以将简单的 html 和 javascript 文件结构上传到 heroku?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10551273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to upload a simple html and javascript file structure to heroku?
提问by Jeremy Smith
I'm trying to deploy an open source project of mine to heroku, it is by necessity very simple with just static html and javascript. But do they not support static sites? I'd rather not make it a Sinatra project if I don't plan on ever using anything but html and javascript.
我正在尝试将我的一个开源项目部署到 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/ | [email protected]:quiet-ice-4769.git
Git remote heroku added
~/sites/d4-site $ git remote -v
heroku [email protected]:quiet-ice-4769.git (fetch)
heroku [email protected]: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
采纳答案by Tiago Peczenyj
You can use rack to do this:
您可以使用机架来执行此操作:
https://devcenter.heroku.com/articles/static-sites-on-heroku
https://devcenter.heroku.com/articles/static-sites-on-heroku
or you can use something like Octopress/Jekyll who uses sinatra.
或者您可以使用使用 sinatra 的 Octopress/Jekyll 之类的东西。
But you need a minimum stack to serve html static content
但是您需要一个最小堆栈来提供 html 静态内容
回答by pkanane
A simple way is to masquerade the HTML app as a PHP App. Heroku properly identifies PHP apps.
一种简单的方法是将 HTML 应用程序伪装成 PHP 应用程序。Heroku 正确识别 PHP 应用程序。
- Rename your index.html file to home.html.
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"); ?>
In your command line on the machine you are pushing from, type:
git add .
git commit -m 'your commit message'
git push heroku master
- 将您的 index.html 文件重命名为 home.html。
创建一个 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 should properly detect your app now as a php app:
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 Thanks to lemiffe for his blog post: http://www.lemiffe.com/how-to-deploy-a-static-page-to-heroku-the-easy-way/
疯狂感谢 lemiffe 的博文:http: //www.lemiffe.com/how-to-deploy-a-static-page-to-heroku-the-easy-way/
回答by Harlan T Wood
Here is a more elegant method: Just add a file called package.json
which tells Heroku to use harpas your server:
这是一个更优雅的方法:只需添加一个名为的文件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": "*"
}
}
and then deploy to Heroku. Done!
然后部署到 Heroku。完毕!
Further information: https://harpjs.com/docs/deployment/heroku
回答by qed
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:
如果入口点是main.html
,请index.php
使用以下单行内容创建:
<?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.
转到http://myApp.herokuapp.com/,您的应用程序现在应该在线。
回答by Scrotch
There's a very easy way to do it just in case anyone found the above answers hard to follow.
You have your static website with the root at index.html
(say), now you want to diploy it to Heroku, how?
有一种非常简单的方法可以做到,以防万一有人发现上述答案难以理解。
您的静态网站的根目录为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 -
{}
Now simply run git push heroku master
and you're done!
现在只需运行即可git push heroku master
完成!
回答by user4920718
Follow this steps
按照以下步骤操作
Step 1
第1步
Type touch composer.json index.php index.html
类型 touch composer.json index.php index.html
Step 2in the index.php type:
在 index.php 类型中的第 2 步:
<?php include_once("index.html"); ?>
and in the composer.json type {}
并在 composer.json 中输入 {}
Step 3
第 3 步
git add .
git commit -m "[your message]"
git push ['yourrepo'] ['yourbranch']
回答by Ronier Lopez
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:
我知道这可能有点旧,但我最终使用 Vienna Gemw 来部署它,基本上它是一个小型 Rack 应用程序,只需几行即可让您提供公共文件夹(css、图像、js、html)中的所有内容红宝石:
require 'vienna'
run Vienna
Also, for deploying this on heroku you need to create a Gemfile:
此外,为了在 heroku 上部署它,您需要创建一个 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:
然后运行 bundle install,如果你没有安装 bundle gem,只需在你的终端上运行:
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/
就这些,您可以了解更多信息:http: //kmikael.com/2013/05/28/creating-static-sites-in-ruby-with-rack/
回答by Hishalv
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.
嗯……我认为 heroku 拒绝该应用程序的一个原因可能是它试图检测 rails 3.1.x 应用程序中的资产管道。
Why not create your app on the default stack Bambooby running just
为什么不通过运行在默认堆栈Bamboo上创建您的应用程序
heroku create
Then all your js and css can go into public folder in rails app with asset pipeline deactivated.
然后,您的所有 js 和 css 都可以进入 rails 应用程序中的公共文件夹,并停用资产管道。
回答by Aamir M Meman
Well , whenever your Web-page's contain HTML, CSS and JavaScript , so follow just 2 steps :
好吧,只要您的网页包含 HTML、CSS 和 JavaScript,那么只需执行 2 个步骤:
1) Make one file give name as index.html (keep evreything in it) ex:script,stylesheet & body.
1)将一个文件命名为index.html(保留其中的所有内容)例如:脚本,样式表和正文。
2) Now, change these file, copy and paste these same file but change domain to index.php
2)现在,更改这些文件,复制并粘贴这些相同的文件,但将域更改为 index.php
Then deploy on a Heroku.
然后部署在 Heroku 上。
Hence this method will help you to deploy your Web-Pages
因此,此方法将帮助您部署您的网页