我有一个简单的Sinatra应用程序。在本地机器上正常工作。
将它部署到Heroku,我不断在日志上获得404.
我保证我会在网上搜索大约5小时,并且无法解决这个问题。
我得到的日志是:
2014-11-08T00:17:12.537150+00:00 heroku[web.1]: Starting process with command `bundle exec rackup config.ru -p 51609`
2014-11-08T00:17:12.840926+00:00 heroku[web.1]: Process exited with status 143
2014-11-08T00:17:16.370395+00:00 app[web.1]: [2014-11-08 00:17:16] INFO WEBrick 1.3.1
2014-11-08T00:17:16.370515+00:00 app[web.1]: [2014-11-08 00:17:16] INFO ruby 2.0.0 (2014-10-27) [x86_64-linux]
2014-11-08T00:17:16.371280+00:00 app[web.1]: [2014-11-08 00:17:16] INFO WEBrick::HTTPServer#start: pid=2 port=51609
2014-11-08T00:17:16.745163+00:00 heroku[web.1]: State changed from starting to up
2014-11-08T00:17:35.351527+00:00 heroku[router]: at=info method=GET path="/" host=pacific-refuge-6392.herokuapp.com request_id=406b2ea5-5898-4a86-8a26-6bf71f70d3f6 fwd="200.170.116.105" dyno=web.1 connect=3ms service=22ms status=404 bytes=319
2014-11-08T00:17:35.352064+00:00 app[web.1]: 200.170.116.105 - - [08/Nov/2014 00:17:35] "GET / HTTP/1.1" 404 18 0.0030
我的 Gemfile 是这样的:
ruby '2.0.0'
source "https://rubygems.org"
gem 'sinatra-base'
gem 'sinatra-assetpack'
gem 'sinatra-asset-pipeline'
gem 'sass'
gem 'datamapper'
gem 'pony'
group :production do
gem "pg"
gem "dm-postgres-adapter"
end
group :development, :test do
gem "sqlite3"
gem "dm-sqlite-adapter"
end
Proclife:
web: bundle exec rackup config.ru -p $PORT
我用红宝石代替了机架和其他一些我找到的变种。
Config.ru
require './my_launch'
run Sinatra::Application
最后,我的应用:my_launch.rb :
require 'sinatra/base'
require 'sinatra/assetpack'
require 'sass'
require 'data_mapper'
require 'dm-migrations'
require 'pony'
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/mylaunch.db")
class Users
include DataMapper::Resource
property :id, Serial
property :email, String, :required => true, :format => :email_address
property :created_at, DateTime
end
DataMapper.finalize.auto_upgrade!
class MyLaunch < Sinatra::Base
set :sessions, true
register Sinatra::AssetPack
assets do
css :main, [
'/css/*.css'
]
css_compression :sass
end
get '/' do
erb :index
end
post '/' do
n = Users.new
n.email = params[:email]
n.created_at = Time.now
n.save
redirect '/obrigado'
end
get '/obrigado' do
erb :obrigado
end
get '/admin' do
@users = Users.all :order => :id.desc
erb :admin
end
run! if app_file == $0
end
我的数据库似乎没问题。 为了测试我启动了heroku控制台并在我的数据库上创建了一个条目。 通过需要my_launch.rb并制作Users.new及以后的Users.save
答案 0 :(得分:1)
在您的配置文件中,您的调用run Sinatra::Application
不同于您的Sinatra继承类,其中定义了所有路由。将其更改为
require './my_launch'
run MyLaunch