Heroku Cedar pure rack static site

百般思念 提交于 2019-12-04 17:42:52

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".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!