2016-12-29 1 views
0

ローカルマシンで実行すると、サーバーを実行するapp.rbというファイルがあります。サーバーがHeroku上で動作するように、私はHerokuにapp.rbを配備したいと思います。私はroutes.rbでルートを作る必要があると思う。これはどうすればいいですか?rails + heroku:routes.rbファイルのルートをapp.rbファイルに

このconfig.ruある:

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

これはコードパスガイド(https://guides.codepath.com/android/Google-Cloud-Messaging#step-3-setup-web-server)からapp.rbにおけるWebサーバのコードである:

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の例を始めると、サンプルのWebページが表示されますe。私はとconfig.ruファイル「実行シナトラ:: Application」を編集し、Herokuのにデプロイする場合は、もう例のWebページを表示することができない、とだけ

+0

詳細を教えてください。 'app.rb'はアプリケーションサーバーのRackアプリケーションを定義していますか? 'config.ru'を貼り付けることができますか? –

+0

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

+0

ありがとう、私はapp.rbとconfig.ruコードを入れました。私はRackアプリが何であるか分かりません。このコードは、プッシュ通知を送受信するサーバーです。 – mjpablo23

答えて

0
require '/.app.rb' 

この「見つかりません」と言います代わりに./app.rbにする必要があります。

関連する問題