Private pub channel js file not found
Here's my application.js file
//= require jquery
//= require jquery_ujs
//= require foundation
//= require private_pub
//= require_tree .
My private_pub.yml file
development:
server: "http://localhost:9292/tweets/create"
secret_token: "secret"
test:
server: "http://localhost:9292/tweets/create"
secret_token: "secret"
production:
server: "http://localhost:9292/tweets/create"
secret_token: "89e004720af45e61a350a30cf7ee3f50163ca141a02ea130db0b5007a0b75058"
signature_expiration: 3600 # one hour
A part of my page which wants to subscribe to a channel
<%= form_for @tweet, url: tweets_path, method: :post, remote: true do |f| %>
<%= f.text_area :body, id: 'tweet-box', placeholder: "What's goin on..." %>
<%= f.submit 'tweet', id: 'tweet-btn', class: 'button' %>
<% end %>
<div id="map-canvas" />
<%= subscribe_to '/'tweets/create' %>
The create.js.erb file for my create action in the tweets controller
<% publish_to "/tweets/create" do %>
var swBound_tweet = new google.maps.LatLng(<%= @tweet.location.latitude %>,<%= @tweet.location.longitude %>)
var neBound_tweet = new google.maps.LatLng(<%= @tweet.location.latitude %>,<%= @tweet.location.longitude %>)
var tweet_coords = new google.maps.LatLngBounds(swBound_tweet, neBound_tweet)
var tweet_overlay = new Tweet(tweet_coords,"<%= @tweet.body %>", window.map)
<% end %>
I started the faye server with this:
bundle exec rackup private_pub.ru -s thin -E development config.ru
also tried with
bundle exec rackup private_pub.ru -s thin -E production config.ru
I'm getting this error in the browser console:
GET http://localhost:9292/tweets/create.js 404 (Not Found)
I'm getting this error in the faye server logs:
127.0.0.1 - - [25/Jan/2014 11:16:56] "GET /tweets/create.js HTTP/1.1" 404 767 0.1431
I've changed the channel name several times in all the files where it is mentioned but I still get the same problem. I'm using:
ruby - 2.0.0
rails - 3.2.13
faye - 1.0.1
private_pub - 1.0.3
Your whole setup is wrong. In your private_pub.ru file put this:
require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"
Faye::WebSocket.load_adapter('thin')
PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
run PrivatePub.faye_app
in app/config/private_pub.yml put this:
development:
server: "http://localhost:9292/faye"
secret_token: "secret"
test:
server: "http://localhost:9292/faye"
secret_token: "secret"
production:
server: "http://production-host.tld:9292/faye"
secret_token: "generate_a_hash_for_this"
signature_expiration: 3600 # one hour
Than start faye like this:
rackup private_pub.ru -s thin -E production
Than it should work.
Oh sorry..I mistakenly wrote private_pub.ru in place of private_pub.yml in my question. My private_pub.ru file has this
require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"
Faye::WebSocket.load_adapter('thin')
PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
run PrivatePub.faye_app
and private_pub.yml has this
development:
server: "http://localhost:9292/tweets/create"
secret_token: "secret"
test:
server: "http://localhost:9292/tweets/create"
secret_token: "secret"
production:
server: "http://localhost:9292/tweets/create"
secret_token: "89e004720af45e61a350a30cf7ee3f50163ca141a02ea130db0b5007a0b75058"
signature_expiration: 3600 # one hour
I apologize again for the silly mistake. Thanks
I haven't checked it but I guess there is some hard coded reference for the faye url so it has to be like in the config file below.
development:
server: "http://localhost:9292/faye"
secret_token: "secret"
test:
server: "http://localhost:9292/faye"
secret_token: "secret"
production:
server: "http://localhost:9292/faye"
secret_token: "89e004720af45e61a350a30cf7ee3f50163ca141a02ea130db0b5007a0b75058"
signature_expiration: 3600 # one hour
I initially used the same config file you've given above, but when I looked in the network tab of my google chrome browser, it had initiated a GET request for
http://localhost:9292/faye.js
I don't know why it is looking for faye.js file. When I changed the url in config file. Eg: for "http://localhost:9292/xyz" it is looking for "http://localhost:9292/xyz.js" and hence gives a 404 error
The issue surprisingly got fixed when i ran the application on windows
Anyone knows why this happens?
Still trying to figure it out. Specially since if I wait long enough it fixes itself, but that won't stop my boss from yelling at me while we wait xD.
My config looks exactly like the private_pub.yml described here. Only difference is that i run it from rails instead of rackup, like this:
RAILS_ENV=production bundle exec thin -p 9292 -e production -R private_pub.ru --timeout 60 start -d