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

Posted

技术标签:

【中文标题】是否可以将简单的 html 和 javascript 文件结构上传到 heroku?【英文标题】:Is it possible to upload a simple html and javascript file structure to heroku? 【发布时间】:2012-05-20 01:05:00 【问题描述】:

我正在尝试将我的一个开源项目部署到 heroku,它必须非常简单,只需要静态 htmljavascript。但他们不支持静态网站吗?如果我不打算使用除 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

【问题讨论】:

【参考方案1】:

有一种更简单的方法可以做到这一点,以防万一有人发现其他答案难以理解。

假设您有一个根为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 即可完成!

【讨论】:

【参考方案2】:

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

【讨论】:

【参考方案3】:

按照这些步骤进行

第 1 步

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

第 2 步 在 index.php 类型中:

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

在 composer.json 中输入

第三步

git add .

git commit -m "[your message]"

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

【讨论】:

【参考方案4】:

这是一个更优雅的方法:只需添加一个名为 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

【讨论】:

在所有答案中,这是截至 2016 年 11 月的有效答案 是的,这个又快又简单 harp server,由于某种原因,无法加载less file。尝试使用上面的php answer 并且有效。虽然,这个解决方案非常简单。谢谢...【参考方案5】:

这对我有用:

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/,您的应用现在应该已经上线了。

【讨论】:

【参考方案6】:

好吧,只要您的网页包含 HTML、CSS 和 JavaScript,只需执行 2 个步骤:

1) 将一个文件命名为 index.html(保留所有内容)例如:脚本、样式表和正文。

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

然后在 Heroku 上部署。

因此此方法将帮助您部署您的网页

【讨论】:

【参考方案7】:

我知道这可能有点旧,但我最终使用 Vienna Gemw 来部署它,基本上它是一个小型 Rack 应用程序,它可以让您提供公共文件夹中的所有内容(css、图像、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/

【讨论】:

【参考方案8】:

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

    将 index.html 文件重命名为 home.html。

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

    &lt;?php include_once("home.html"); ?&gt;

    在要推送的机器上的命令行中,键入:

    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/

【讨论】:

这更简单,应该被接受为正确答案 注意:我需要先添加 composer.json 才能让它工作。 devcenter.heroku.com/articles/… 真的,真的很好。为我节省了很多使用 Node.js 的麻烦,非常感谢! 您可能需要执行 git init 来获取 git 命令和执行 heroku create 来获取 heroku 命令工作 为了更简单,您可以将 index.html 重命名为 index.php【参考方案9】:

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

为什么不在默认堆栈Bamboo上创建您的应用程序,只需运行

heroku create

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

【讨论】:

一想到使用 Rails 提供静态内容,我就想伤害别人 :) 当您只有 js/html/css 时,它会查找 node.js 应用程序。无论您尝试使用哪个堆栈运行它,它都会在找不到它时失败。【参考方案10】:

你可以使用 rack 来做到这一点:

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

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

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

【讨论】:

OP 没有要求 Ruby 解决方案。 再读一遍我的句子

以上是关于是否可以将简单的 html 和 javascript 文件结构上传到 heroku?的主要内容,如果未能解决你的问题,请参考以下文章

javascrip函数简单介绍

javascrip基础课程-1

JavaScrip入门

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

javascrip基础以及一个计算器的小案例

javascrip基础以及一个计算器的小案例