Heroku雪松纯机架静态网站 [英] Heroku Cedar pure rack static site

查看:219
本文介绍了Heroku雪松纯机架静态网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试合并两个用于托管静态网站的教程:



基本上我希望能够在雪松堆叠上的旧竹教程中做你所做的。我可以让雪松教程工作,但是当我尝试修改它以提供文件时,我收到一个错误消息。



我看了一下以下帖子,但github回购似乎不再起来,我不能当我尝试在本地按照第一个教程运行网站时,出现以下错误:

$ b




$ b

  martin @ crunchbang:〜/ code / martinrichards.me $ rackup -p 9292 config.ru& 
[2] 4065
martin @ crunchbang:〜/ code / martinrichards.me $ /home/martin/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/ lib / rack / builder.rb:40:在`eval'中:/home/martin/code/martinrichards.me/config.ru:2:语法错误,意外的tIDENTIFIER,期望'}'(SyntaxError)
200 ,... | env |
...

我把我的到目前为止, Github ,任何帮助将不胜感激。

解决方案

首先,您的 config.ru 几乎完全是空的。看起来你像Heroku教程一样遵循相同的网站结构,所以从这样的config.ru开始:

 使用Rack :: Static,
:urls => [/ stylesheets,/ images],
:root =>public

run lambda {| env |
[
200,
{
'Content-Type'=>'text / html',
'Cache-Control'=>'public,max-age = 86400'
},
File.open('public / index.html',File :: RDONLY)
]





$ b

由于您在Cedar上,因此使用 Procfile 来启动你的进程。因此,将一个名为 Procfile (无扩展名)的文件添加到您的根目录中,并在其中添加以下内容:

web:bundle exec rackup config.ru -p $ PORT



应该这样做。



如果你想使用Sinatra,Heroku在Cedar的Ruby网站上有一步一步的tuturioal: https://devcenter.heroku.com/articles/ruby



编辑:



事实证明,您的 config.ru 中存在行结尾问题。这就是为什么GitHub没有正确显示文件。你的行结束符是 ^ M ,它们是DOS / Windows / Mac OS 9行尾。这就是为什么Ruby在第二行发生错误 - 这是第一次换行。不确定你正在使用哪种文本编辑器,但它可能支持更改行尾。切换它们的Unix,并且都应该正常工作。如果您正在寻找可以执行此操作的文本编辑器,请查看 Sublime Text 2 。行结束功能位于视图菜单中。



由于您正在构建纯粹的Rack应用程序,因此实际上并不需要 Procfile ,因为默认的Heroku Cedar buildpack会为你检测 config.ru 。但是,一旦开始使用其他框架(如Sinatra), Procfile 就会派上用场。另外,如果你在Mac上,你可以使用工头来模拟Heroku的旋转处理。请注意, Profile 没有扩展名,并且大写字母P。


I've been trying to consolidate two tutorials for hosting static sites:

Basically I want to be able to do what you do in the old bamboo tutorial on the cedar stack. I can get the cedar tutorial to work, but when I try modify it to serve files I get an error.

I have had a look at the following post, but the github repo doesn't seem to be up any longer and I can't quite figure out where I've gone wrong.

When I try run the site locally as per the first tutorial, I get the following error:

martin@crunchbang:~/code/martinrichards.me$ rackup -p 9292 config.ru &
[2] 4065
martin@crunchbang:~/code/martinrichards.me$ /home/martin/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval':     /home/martin/code/martinrichards.me/config.ru:2: syntax error, unexpected tIDENTIFIER, expecting '}' (SyntaxError)
200, ... |env|"
...

I've put what I've got so far on Github, any help will be much appreciated.

解决方案

Well, first, your config.ru is almost completely empty. Looks like you're following the same site structure as the Heroku tutorial, so start with a config.ru like this:

use Rack::Static, 
  :urls => ["/stylesheets", "/images"],
  :root => "public"

run lambda { |env|
  [
    200, 
    {
      'Content-Type'  => 'text/html', 
      'Cache-Control' => 'public, max-age=86400' 
    },
    File.open('public/index.html', File::RDONLY)
  ]
}

Since you are on Cedar, it is helpful to use a Procfile to start up your processes. So add a file called Procfile (no extension) to your root, and put the following inside it:

web: bundle exec rackup config.ru -p $PORT

That should do it.

If you want to use Sinatra, Heroku has a step-by-step tuturioal for Ruby sites on Cedar: https://devcenter.heroku.com/articles/ruby

EDIT:

As it turns out, you're having line-endings problems in your config.ru. That's why GitHub is not displaying the file correctly. Your line endings are ^M, which are DOS/Windows/Mac OS 9 line-endings. That's why Ruby is throwing an error on line 2 - it's the first line break. Not sure what text-editor you are using, but it probably supports changing line endings. Switch them Unix, and all should work fine. If you're looking for a text editor that can do this, check out Sublime Text 2. The line-endings functionality is in the "View" menu.

Since you are building a pure Rack app, you actually don't need a Procfile, since the default Heroku Cedar buildpack will detect the config.ru for you. However, the Procfile comes in handy once you start using other frameworks (like Sinatra). Plus, if you are on a Mac, you can use Foreman to simulate Heroku's spin-up process. Note that Profile is without an extension and with a capital "P".

这篇关于Heroku雪松纯机架静态网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆