I am trying to make a Chat web application based on Rails using "private_pub" gem which works perfectly on my localhost server. Now my site is hosted on DigitalOcean and i want to push chat code on the server to see how real-time chat app will work.
This is my private_pub.yml file
development:
server: "http://localhost:9292/faye"
secret_token: "secret"
test:
server: "http://localhost:9292/faye"
secret_token: "secret"
staging:
server: <%= ENV["FAYE_URL"] %>
secret_token:"secret_key"
signature_expiration: 3600 # one hour
production:
server: <%= ENV["FAYE_URL"] %>
secret_token: "secret_key"
signature_expiration: 3600 # one hour
My question is What should i have to do to make it work on any Linux server ( Here Digital Ocean for me). I am using Nginx server on DigitalOcean.
What should be the value for FAYE_URL in private_pub.yml file?
rackup private_pub.ru -s thin -E production
Do i have to run rack command on my server terminal? Or is there any other way to host Faye on a different server then?
I don't know Digital Ocean's servers.
I have worked with a Google Cloud Engine virtual machine with OS Ubuntu 14.04.
Here's how I configured my pub/sub app that uses Faye with a dns resolver in HTTPS on Nginx web server with Passenger.
Faye Server
I set up the Faye server, as a Rack application, to start automatically at boot through the 'Thin' web server.
Script to start/stop Thin with params: thin-configuration-file, faye-rackup-server-script.
/home/user/apps/myapp/config/thin.sh
so I set the execution permissions for the script thin.sh
-rwxr-xr-x 1 user user ... thin.sh*
then I defined the script thin.sh as a service
lrwxrwxrwx 1 root root ... thin -> /home/user/apps/myapp/config/thin.sh*
and finally I configured the boot on startup
I have defined the parameters necessary for the script thin.sh (as params in $CMD in config/thin.sh)
First the thin web server configuration file
/home/user/apps/myapp/config/thin.yml
and then the Faye server startup script (via rackup)
/home/user/apps/myapp/faye.ru
at this point the automatic start of faye server is set.
At boot '/etc/init.d/thin' service start 'thin server' with config/thin.yml executnig rackup script 'faye.ru'.
Faye client
I parametrized the urls for faye client
/home/user/apps/myapp/config/initializers/urls.rb
I included faye client javascripts in
/home/user/apps/myapp/app/views/layouts/application.html.erb
so then they are charged when you access the app
The Faye client is created when you access the page where there are your chat rooms (as channel).
The right place is
/home/user/apps/myapp/app/assets/javascript/application.js
Sending a new message from client to server Faye:
(creating a new Message model with a call remote: true (ajax))
called by create.js rensponse triggerd by controller_message#create as ajax response renderer
/home/user/apps/myapp/app/helpers/application_helper.rb
That's all
For a better comprehension, I enclose Nginx configuration file