Setup PrivatePub or Faye on heroku

In this post I am  going to show how to setup private_pub server on heroku. Private Pub gem is a very nice solution for pushing real time data and it’s open-source . For using the private_pub gem we have to create two application on heroku. First one for our rails app and second one for private_pub server.

Folder structure for private_pub server application is like the below one

fayeserver

config ———–> private_pub.yml
                            application.rb
                            boot.rb
script ————> rails

Gemfile

Gemfile.lock

Procfile

private_pub.ru

Note: bold represent folder and other represent file.

“private_pub.yml” and “private_pub.ru” are created by private_pub gem using rails g private_pub:install

Gemfile has following gems

source ‘https://rubygems.org
    gem ‘rails’,’3.2.12′
    gem ‘private_pub’
    gem ‘thin’
    gem ‘foreman’
After adding the gem ,  bundle it. Then run “rails g private_pub:install”.
Initialize the repository by git init.
After that create a heroku app using “heroku apps:create fayserver”. I am using app name as “fayserver” but it can be changed.
Then change the private_pub.yml file content to
production:
  secret_token: “batkaro”
  signature_expiration: 86400 # one day
After that commit the code and push the code to heroku .
Now finally  we are ready to  use it. 🙂

You can checkout my github repository for fayserver code

16 thoughts on “Setup PrivatePub or Faye on heroku

  1. Hi there.. I wanted to thank you for this guide. I haven’t found anyone else trying to explain this process online, so I appreciate it. However, I am having trouble getting it to work. I have created a blank directory and set up a Gemfile with the contents you provide. Bundler works fine, but then when I type “rails g private_pub:install”, Rails just outputs its help text. Is there something I need to do with the directory to have it enable the proper use of the ‘rails’ command? I have never tried to use the ‘rails’ command outside of a rails app before, so I’m a little lost. Any help would be appreciated. Thanks!

  2. Hi,

    Thanks so much for your tutorial. It has been really helpful.

    I’ve successfully set up the fayeserver on another Heroku app, but when I try to access the fayserver (eg. faye.herokuapp.com) from my rails app (app.herokuapp.com), I get a cross origin access not allowed error. I’m guessing that because the 2 domains were different, so I got the error.

    Has this happened to you? Do you know how I can resolve this?

    Thanks

    • Thanks again. I actually cloned your fayeserver repo and just changed the secret key.

      My rails app is a pretty default setup (sorry, it was hosted on a private repo :() I made sure all the configs matched your files as well…

      Thanks for your help,
      Henry

      • Oh, so silly of me. I forgot to add and commit a file that I changed for the token.
        Not it works 100%.

        I’m really sorry and thanks for all your help. The cross origin was really misleading.

        Thanks!
        Henry

  3. Thanks for your help.

    Although the fayeserer works, I sometimes still get “is not allowed by Access-Control-Allow-Origin.” on Chrome. Not sure why that is the case, but it works. Hopefully it won’t affect functionality…

  4. Hello,

    My chat application working my on local system.Buy when i deployed it on heroku it creating problem.I have done all set-up on heroku. I tried it with both url : http://ramfayeserver.herokuapp.com/faye and my own application http://fayeserver.herokuapp.com/faye.but couldn’t get success.I noticed that both url faye.js content changed.Is there is an issue.

    I have also changed faye version with ‘0.8.8’.

    When I try to send message with console I am getting blank array please see details:

    curl http://fayeserver.herokuapp.com/faye -d ‘message={“channel”:”/messages/new”, “data”:”hello”, “ext”:”{‘private_pub_token’:’batkaro’}”}’
    result : [ ]

    I am using same secret_token like example.

  5. Pingback: CheckCheetah: A Rails Web App for Ordering and Paying at a Bar « Rob Williams

Leave a reply to hareramrai Cancel reply