I'd like to configure ActionCable to work on Heroku.
I've tried changing my cable.yml file into cable.yml.erb so I can evaluate ENV['REDISTOGO_URL'] like so:
cable.yml.erb:
development:
adapter: async
test:
adapter: async
production:
adapter: redis
url: <%= ENV["REDISTOGO_URL"] %>
But now I'm getting the following error:
2016-11-23T02:24:20.551375+00:00 app[web.1]: E, [2016-11-23T02:24:20.551320 #4] ERROR -- : There was an exception - NoMethodError(undefined method `fetch' for nil:NilClass)
2016-11-23T02:24:20.551478+00:00 app[web.1]: E, [2016-11-23T02:24:20.551408 #4] ERROR -- : /app/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.0.1/lib/action_cable/server/configuration.rb:24:in `pubsub_adapter'
2016-11-23T02:24:20.551480+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.0.1/lib/action_cable/server/base.rb:72:in `block in pubsub'
2016-11-23T02:24:20.551481+00:00 app[web.1]: /app/vendor/ruby-2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
2016-11-23T02:24:20.551482+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.0.1/lib/action_cable/server/base.rb:72:in `pubsub'
If I hard code the url it will work:
cable.yml:
development:
adapter: async
test:
adapter: async
production:
adapter: redis
url: redis://redistogo:xyz42#sculpin.redistogo.com:10903/
But I think I shouldn't commit the actual url.
Is there anyway around this?
Note: I found this chunk of code and it seems like it might help but I'm not sure.
My project is at mbigras/depot
Try renaming cable.yml.erb to cable.yml itself.
On my local machine it worked for me:
development:
adapter: redis
url: <%= ENV["REDIS_URL"] %>
Related
I am trying to deploy Strapi on Heroku
But it does not work. I get this log
2020-05-27T15:04:05.012958+00:00 app[web.1]: > strapi-oskogen-mongodb#0.1.0 start /app
2020-05-27T15:04:05.012959+00:00 app[web.1]: > node server.js
2020-05-27T15:04:05.012960+00:00 app[web.1]:
2020-05-27T15:04:08.188595+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'count' of module exports inside circular dependency
2020-05-27T15:04:08.188639+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2020-05-27T15:04:08.189164+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
2020-05-27T15:04:08.189299+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
2020-05-27T15:04:08.189381+00:00 app[web.1]: (node:23) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
2020-05-27T15:04:12.308848+00:00 app[web.1]: [2020-05-27T15:04:12.308Z] error Error: listen EADDRNOTAVAIL: address not available 52.54.48.43:31639
2020-05-27T15:04:12.308857+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1296:21)
2020-05-27T15:04:12.308858+00:00 app[web.1]: at listenInCluster (net.js:1361:12)
2020-05-27T15:04:12.308859+00:00 app[web.1]: at GetAddrInfoReqWrap.doListen [as callback] (net.js:1498:7)
2020-05-27T15:04:12.308859+00:00 app[web.1]: at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:68:8)
2020-05-27T15:04:22.927720+00:00 heroku[web.1]: Stopping all processes with SIGTERM
I use MongoDB on Atlas. It works well on localhost both dev and prod environment.
My production files:
server.js
database.js
response.js
app settings
Where did I miss something?
Which is the value of process.env.HOST. For some reason different from 0.0.0.0 (just a shot in the dark - https://strapi.io/documentation/3.0.0-beta.x/migration-guide/migration-guide-beta.19-to-beta.19.4.html#listened-host-changed)
I had to change server.js file (port 443):
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 443),
admin: {
auth: {
secret: env('ADMIN_JWT_SECRET'),
},
},
});
My database.js file:
module.exports = ({ env }) => ({
defaultConnection: "default",
connections: {
default: {
connector: "mongoose",
settings: {
uri: env("DATABASE_URI"),
ssl: { rejectUnauthorized: false }
},
options: {
ssl: true,
authenticationDatabase: "",
useUnifiedTopology: true,
pool: {
min: 0,
max: 10,
idleTimeoutMillis: 30000,
createTimeoutMillis: 30000,
acquireTimeoutMillis: 30000
}
},
},
},
});
I hope it will help to somebody who has the same problem :-)
Not sure if it's what #Rochadsouza meant, but I got the same error and what finally solved the issue in my case was to set the host to 0.0.0.0. For some reasons, the host cannot be the app url, it needs to allow all hosts on Heroku. I was setting the host in server.js using env('HOST', '0.0.0.0') but had the HOST env var set to my app url on Heroku...
Hope it saves some time to others facing the same error.
This is the first time I'm trying to deploy my app and I keep getting this message when I try to visit my app. Initially, I set config.assets.initialize_on_precompile = false and then had to run RAILS_ENV=production bundle exec rake assets:precompile, and that seemed to work. I pushed the changes back up and am still getting this "something went wrong" message.
Here is the relevant output from the heroku log:
2013-11-23T07:26:41.379104+00:00 heroku[web.1]: State changed from starting to up
2013-11-23T07:26:43.642205+00:00 app[web.1]: => Call with -d to detach
2013-11-23T07:26:43.642205+00:00 app[web.1]: => Booting WEBrick
2013-11-23T07:26:43.642205+00:00 app[web.1]: => Rails 3.2.13 application starting in production on http://0.0.0.0:25369
2013-11-23T07:26:43.642205+00:00 app[web.1]: => Ctrl-C to shutdown server
2013-11-23T07:26:43.642205+00:00 app[web.1]: Started GET "/" for 50.131.49.136 at 2013-11-23 07:26:43 +0000
2013-11-23T07:26:43.731222+00:00 heroku[router]: at=info method=GET path=/ host=blooming-garden-2746.herokuapp.com fwd="50.131.49.136" dyno=web.1 connect=2ms service=124ms status=500 bytes=643
2013-11-23T07:26:43.728706+00:00 app[web.1]: app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___52334082019471513_69845865556860'
2013-11-23T07:26:43.728706+00:00 app[web.1]:
2013-11-23T07:26:43.728706+00:00 app[web.1]: ActionView::Template::Error (mystylesheet.css isn't precompiled):
2013-11-23T07:26:43.728706+00:00 app[web.1]: 2: <html>
2013-11-23T07:26:43.728706+00:00 app[web.1]: 3: <head>
2013-11-23T07:26:43.728706+00:00 app[web.1]: 4: <title>Hire Monkey | <%= yield(:title) %></title>
2013-11-23T07:26:43.728706+00:00 app[web.1]: 5: <%= stylesheet_link_tag "mystylesheet", :media => "all" %>
2013-11-23T07:26:43.728706+00:00 app[web.1]: 6: <%= stylesheet_link_tag 'homecss' if params[:action] == 'home' %>
2013-11-23T07:26:43.728706+00:00 app[web.1]: 7: <%= stylesheet_link_tag 'mainbg' if params[:action] != 'home' %>
2013-11-23T07:26:43.728870+00:00 app[web.1]:
2013-11-23T07:26:43.728706+00:00 app[web.1]: 8: <!--I removed the default stylesheet_link_tag and the application.css file to prevent my stylesheets from compiling together so I could display the homepage background image on the homepage only-->
2013-11-23T07:26:43.728870+00:00 app[web.1]:
2013-11-23T07:26:43.729146+00:00 app[web.1]: Processing by JobsController#home as HTML
2013-11-23T07:26:43.729146+00:00 app[web.1]: Rendered jobs/home.html.erb within layouts/application (18.0ms)
2013-11-23T07:26:43.729146+00:00 app[web.1]: Completed 500 Internal Server Error in 29ms
Not sure why this was voted down since this is an issue that many are having. Luckily, I discovered what the problem was. In config/environments/production.rb, make sure config.assets.compile is set to true. That solved everything.
I'm trying to sort out how to use the new3 method of the XMLRPC::Client class. This is what I have:
#!/usr/bin/ruby
require "xmlrpc/client"
params = {
host: "https://192.168.1.2",
path: "rpc/api",
port: "443",
proxy_host: "",
proxy_port: "",
user: "username",
password: "password",
use_ssl: "true",
timeout: 300,
}
session = XMLRPC::Client.new3(params)
session.instance_variable_get(:#http).instance_variable_set(:#verify_mode, OpenSSL::SSL::VERIFY_NONE)
sys_ver = session.call('api.systemVersion')
users = session.call("user.listUsers", session)
If I use the new2 method the script will connect and return a 404 error. However, if I use the new3 it returns
/usr/lib/ruby/1.9.1/net/http.rb:762:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
from /usr/lib/ruby/1.9.1/net/http.rb:762:in `open'
from /usr/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
from /usr/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
from /usr/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
from /usr/lib/ruby/1.9.1/net/http.rb:762:in `connect'
from /usr/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
from /usr/lib/ruby/1.9.1/net/http.rb:750:in `start'
from /usr/lib/ruby/1.9.1/xmlrpc/client.rb:535:in `do_rpc'
from /usr/lib/ruby/1.9.1/xmlrpc/client.rb:420:in `call2'
from /usr/lib/ruby/1.9.1/xmlrpc/client.rb:410:in `call'
from sat_test.rb:24:in `<main>'
Am I using the new3 method properly?
Also, if I use the new method instead, do I need to set parameter=value for each parameter (proxy_host=, proxy_port=, etc)?
The problem seemed to be more with my script being coded wrong. This is what I have now:
#!/usr/bin/ruby
require "xmlrpc/client"
params = {
host: "REDACTED",
path: "/rpc/api",
use_ssl: "true",
user: "REDACTED",
pass: "REDACTED"
}
client = XMLRPC::Client.new3(params)
client.instance_variable_get(:#http).instance_variable_set(:#verify_mode, OpenSSL::SSL::VERIFY_NONE)
session = client.call('auth.login', params[:user], params[:pass])
sys_ver = session.call('api.systemVersion', session)
users = session.call("user.listUsers", session)
users.each { |uname| puts uname }
I've removed unnecessary arguments in the params hash and made sure everything is properly quoted.
It works and is only leaving me with a 404 error which is a problem with the script. But, at least it connects now and gives me something.
I'm having problems sending email via my Ruby code. You can see my full code on GitHub.
UPDATE: the below code has been amended to reflect suggestions from #Gaurish
UPDATE2: looks like gmail refused the login attempt - I received an email from them to warn me some unknown application tried to access my account but they disabled it
The specific class is here:
require 'net/smtp'
=begin
http://apidock.com/ruby/v1_9_3_125/Net/SMTP/start/class
https://devcenter.heroku.com/articles/config-vars
I added the following config vars to Heroku
heroku config:add GM_USR=xxxx
heroku config:add GM_PSW=xxxx
=end
class Email
def initialize (to, from, subject, body)
#to = to
#from = from
#subject = subject
#body = body
#message = <<MESSAGE_CONTENT
From: User <#{#from}>
To: Integralist <#{#to}>
MIME-Version: 1.0
Content-type: text/html
Subject: #{#subject}
#{#body}
MESSAGE_CONTENT
#smtp = Net::SMTP.new('smtp.gmail.com', 587)
end
def send_email
#smtp.enable_starttls
#smtp.start('furious-wind-9309.herokuapp.com', ENV['GM_USR'], ENV['GM_PSW'], :login) do |smtp|
#smtp.send_message(#message, #from, #to)
end
end
end
I'm calling it like so:
email = Email.new('myemail#gmail.com', params[:email], 'test subject', params[:message]);
email.send_mail
But when I execute the code I get the error displayed on screen: 535-5.7.1 Please log in with your web browser and then try again. Learn more at
I checked the logs and I get...
2012-06-13T08:01:08+00:00 heroku[router]: POST furious-wind-9309.herokuapp.com/contact dyno=web.1 queue=0 wait=0ms service=628ms status=500 bytes=2060
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/logger.rb:15:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `block in call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1416:in `synchronize'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:1060:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:1060:in `block in spawn_threadpool'
2012-06-13T08:01:08+00:00 app[web.1]: 82.69.39.185 - - [13/Jun/2012 08:01:08] "POST /contact HTTP/1.1" 500 2060 0.6254
I know people will likely suggest ActionMailer or Pony, but I'd rather not use those or have those suggested to me please. I'd instead like a solution that helps fix the above code instead.
[Update 1]
If gmail doesn't work for you, you can use SendGrid Addon which gives you upto 200emails per day at no charge.
Here is a sample(taken from docs) on how to use their STMP API with mail gem
require 'mail'
Mail.defaults do
delivery_method :smtp, { :address => "smtp.sendgrid.net",
:port => 587,
:domain => "yourdomain.com",
:user_name => "yourusername#domain.com",
:password => "yourPassword",
:authentication => 'plain',
:enable_starttls_auto => true }
end
mail = Mail.deliver do
to 'yourRecipient#domain.com'
from 'Your Name <name#domain.com>'
subject 'This is the subject of your email'
text_part do
body 'Hello world in text'
end
html_part do
content_type 'text/html; charset=UTF-8'
body '<b>Hello world in HTML</b>'
end
end
Using Sendgrid is much better solution because you also get access Advanced reporting & analyticss which are not available with gmail. Also, there is no restriction on "from" addresses in sendgrid.
With Heroko, you can't send emails directly from localhost because Heroku does not provide an outgoing mail service.
so you will have to consider an external smtp server for sending your emails. popular ones are Gmail & Sendgrid
this is just one trade-off of using a cloud computing platform like heroku.
With Gmail, try doing something like this:
require 'net/smtp'
msg = "your message goes here"
smtp = Net::SMTP.new 'smtp.gmail.com', 587
smtp.enable_starttls
smtp.start(YourDomain, YourAccountName, YourPassword, :login) do
smtp.send_message(msg, FromAddress, ToAddress)
end
If you try:
#email = Email.new('mark.mcdx#gmail.com', params[:email], 'test subject', params[:message])
#email.send_email
Just load up SendGrid as an add-on and it works right out of the box. Plus you get a whole suite of analytics for troubleshooting bounces, deliveries, etc...
I've recently deployed some A/B testing experiments using vanity to my heroku instance. However, whenever I access the dashboard i.e. /vanity The following error shows up in the logs
- ActionView::Template::Error (Connection refused - Unable to connect to Redis on 127.0.0.1:6379):
- 1: <ul class="experiments">
- 2: <% experiments.sort_by { |id, experiment| experiment.created_at }.reverse.each do |id, experiment| %>
- 3: <li class="experiment <%= experiment.type %>" id="experiment_<%=vanity_h id.to_s %>">
- 4: <%= render :file => Vanity.template("_experiment"), :locals => { :id => id, :experiment => experiment } %>
- 5: </li>
-
However, the redis to go url seems to be set up correctly and vanity seems to be able to access it
e.g.
irb(main):011:0> Vanity.playground.connection
=> redis://bluegill.redistogo.com:9231/0
Anyone know what I could be doing wrong ?
my vanity.rb config file is fairly standard
development:
adapter: redis
connection: redis://localhost:6379/0
qa:
adapter: redis
connection: <%= ENV["REDISTOGO_URL"] %>
staging:
adapter: redis
connection: <%= ENV["REDISTOGO_URL"] %>
production:
adapter: redis
connection: <%= ENV["REDISTOGO_URL"] %>
and also the ENV["REDISTOGO_URL"] seems correct
irb(main):012:0> ENV["REDISTOGO_URL"]
=> "redis://redistogo:e1ab3fa23beacbcd481cd4508ad0090c#bluegill.redistogo.com:9231/"
And I can access Redis from the rest of the app, it just seems that Vanity is not picking it up for this template..
Ok, I've figured this one out. When we fork with unicorn I wasn't reconnecting to the correct redis server and instead defaulting to the localhost. This code snippet in unicorn.rb sorts it out.
after_fork do |server, worker|
# the following is *required* for Rails + "preload_app true",
ActiveRecord::Base.establish_connection
Vanity.playground.establish_connection(ENV["REDISTOGO_URL"])
end
I'm sure its similar for other forking servers too.