2016-12-29 40 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

相關問題