2016-12-29 125 views
0

我有一个名为app.rb的文件,当我在本地机器上运行服务器时运行服务器。我想将app.rb部署到Heroku,以便服务器在Heroku上运行。我认为我需要在routes.rb中指向它。我该怎么做呢?rails + heroku:指向routes.rb文件的根目录到app.rb文件

这是config.ru:

require_relative 'config/environment' 
require '/.app.rb' 
run Rails.application 
run Sinatra::Application 

这是app.rb web服务器代码,代码路径从引导件(https://guides.codepath.com/android/Google-Cloud-Messaging#step-3-setup-web-server):

require 'sinatra' 
require 'rest-client' 
require 'sequel' 

# Create a SQLite3 database 

DB = Sequel.connect('sqlite://gcm-test.db') 

# Create a Device table if it doesn't exist 
DB.create_table? :Device do 
    primary_key :reg_id 
    String :user_id 
    String :reg_token 
    String :os, :default => 'android' 
end 

Device = DB[:Device] # create the dataset 

# Registration endpoint mapping reg_token to user_id 
# POST /register?reg_token=abc&user_id=123 
post '/register' do 
    if Device.filter(:reg_token => params[:reg_token]).count == 0 
    device = Device.insert(:reg_token => params[:reg_token], :user_id => params[:user_id], :os => 'android') 
    end 
end 

# Ennpoint for sending a message to a user 
# POST /send?user_id=123&title=hello&body=message 
post '/send' do 
    # Find devices with the corresponding reg_tokens 
    reg_tokens = Device.filter(:user_id => params[:user_id]).map(:reg_token).to_a 
    if reg_tokens.count != 0 
    send_gcm_message(params[:title], params[:body], reg_tokens) 
    end 
end 

# Sending logic 
# send_gcm_message(["abc", "cdf"]) 
def send_gcm_message(title, body, reg_tokens) 
    # Construct JSON payload 
    post_args = { 
    # :to field can also be used if there is only 1 reg token to send 
    :registration_ids => reg_tokens, 
    :data => { 
     :title => title, 
     :body => body, 
     :anything => "foobar" 
    } 
    } 

    # Send the request with JSON args and headers 
    RestClient.post 'https://gcm-http.googleapis.com/gcm/send', post_args.to_json, 
    :Authorization => 'key=' + AUTHORIZE_KEY, :content_type => :json, :accept => :json 
end 

这是procfile:

web: bundle exec puma -C config/puma.rb 

当我按照Ruby on Heroku入门的例子,我可以看到示例webpag即不过,如果我编辑与“运行西纳特拉::应用”的config.ru文件,并将其部署到Heroku的,它是不是能再显示网页例子,只是说:“未找到”

+0

你能提供更多的细节吗? 'app.rb'是否定义了应用程序服务器的Rack应用程序?你可以粘贴你的'config.ru'(如果你有)? –

+0

require_relative'config/environment' require'/.app.rb' 运行Rails.application 运行Sinatra ::应用程序 – mjpablo23

+0

好的,谢谢,我已经把app.rb和config.ru代码放进去了。我不确定Rack应用是什么。该代码是用于接收和发送推送通知的服务器。 – mjpablo23

回答

0
require '/.app.rb' 

这应改为./app.rb

相关问题