Ember CLI and Rails: Error proxying to http://localhost:3000 - ruby-on-rails

I am following this tutorial for Ember CLI and Rails. I am stuck at the point where you are supposed to load the Book model data using the following command in the console:
App.store.findAll('book');
No data is retrieved and the Ember terminal logs show this error:
Error proxying to http://localhost:3000
connect ECONNREFUSED 127.0.0.1:3000
Error: connect ECONNREFUSED 127.0.0.1:3000
at Object.exports._errnoException (util.js:890:11)
at exports._exceptionWithHostPort (util.js:913:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1061:14)
GET /books - - ms - -
However when I visit http://localhost:3000/books (the Rails backend), I get the correct JSON response with all the books. Why is the Ember app not able to retrieve this data and how can I fix it?

Restart the Rails server with:
rails s --binding 0.0.0.0
then restart the ember server.

There are multiple things you need to watch.
Try setting up in your embers config/environment.js for each environment proper URL and settings. More info here.
ENV.contentSecurityPolicy = {
'default-src': "'none'",
'script-src': "'self'",
'font-src': "'self'",
'connect-src': "'self' http://localhost:3000",
'img-src': "'self' data:",
'style-src': "'self' 'unsafe-inline'",
'media-src': "'self'"
};
And you also need to explain Rails app to accept connection outside of the rails app. CORS. Looks for this gem.

Related

Where do I find the error log of a Rails app on the production server?

My app is working fine on a local server. After deploying it on production (AWS EC2), I see this "classic" Rails error page:
I thought that the errors are logged to the file current/log/production.log, but when I looked in it, there's no error captured. I can only see there the following:
I, [2019-06-09T12:12:04.353438 #12855] INFO -- : Started GET "/constact-us" for 185.44.76.84 at 2019-06-09 12:12:04 +0000
I, [2019-06-09T12:12:04.355034 #12855] INFO -- : Processing by MyAppSite::SiteController#contact_us as HTML
There's logged accessing the URL, but not the error message. Where do I find it? I added some pure HTML/image to that template, so I think the error must be related to some issue with assets (and precompilation).
However, where do I find the full error message?
I am looking to the config/environments/production.rb file and regarding logs, there's "only" this line:
config.log_level = :info
Any advise how to figure out the error message?
EDIT: I just realized that I also have integrated Rollbar to the app and it hasn't caught the error either.
EDIT 2: error from the nginx log:
2019/06/09 13:47:14 [error] 987#0: *7824941 upstream prematurely closed connection while reading response header from upstream, client: IP, server: www.my_website.com, request: "GET /contact-us HTTP/1.1", upstream: "http://unix:/tmp/unicorn.myapp_production.sock:/contact-us", host: "www.my_website.com
Thank you

Composer rest server can't connect to ca.org1.example.com

I followed this tutorial to setup myorg/composer-rest-server and everything was working fine till I import card but when I make a GET request to /api/system/ping it returns 500 Error:
{"error":{"statusCode":500,"name":"Error","message":"Error trying login and get user Context. Error: Error trying to enroll user or load channel configuration. Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:7054]","stack":"Error: Error trying login and get user Context. Error: Error trying to enroll user or load channel configuration. Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:7054]\n at client.getUserContext.then.then.catch (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:393:34)\n at <anonymous>\n at process._tickDomainCallback (internal/process/next_tick.js:228:7)"}}
So I checked the logs for rest container, it can't seem to find 127.0.0.1:7054. Here is the error log.
Unhandled error for request GET /api/system/ping: Error: Error trying login and get user Context. Error: Error trying to enroll user or load channel configuration. Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:7054]
at client.getUserContext.then.then.catch (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:393:34)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
So I checked the logs for the container ca.org1.example.com, and it is listening to port 7054
2018/04/01 09:57:25 [DEBUG] CA initialization successful
2018/04/01 09:57:25 [INFO] Home directory for default CA: /etc/hyperledger/fabric-ca-server
2018/04/01 09:57:25 [DEBUG] 1 CA instance(s) running on server
2018/04/01 09:57:25 [INFO] Listening on http://0.0.0.0:7054
I think i need to change 127.0.0.1 to 0.0.0.0 but not sure how to do it the right way. Could also be a firewall issue?
Here's my .composer/cards/restadmin#myserver/connection.json
{"name":"hlfv1","x-type":"hlfv1","x-commitTimeout":300,"version":"1.0.0","client":{"organization":"Org1","connection":{"timeout":{"peer":{"endorser":"300","eventHub":"300","eventReg":"300"},"orderer":"300"}}},"channels":{"composerchannel":{"orderers":["orderer.example.com"],"peers":{"peer0.org1.example.com":{}}}},"organizations":{"Org1":{"mspid":"Org1MSP","peers":["peer0.org1.example.com"],"certificateAuthorities":["ca.org1.example.com"]}},"orderers":{"orderer.example.com":{"url":"grpc://orderer.example.com:7050"}},"peers":{"peer0.org1.example.com":{"url":"grpc://peer0.org1.example.com:7051","eventUrl":"grpc://peer0.org1.example.com:7053"}},"certificateAuthorities":{"ca.org1.example.com":{"url":"http://ca.org1.example.com:7054","caName":"ca.org1.example.com"}}}
I'm using AWS EC2
OS: Ubuntu 16.04.3 LTS,
Docker: 17.12.0-ce,
Composer: v0.19.0
Fabric: v1.1
Which card have you imported? If it is the restadmin card, I think you may have imported a Card containing an expired One-Time secret. After the rest admin card was used to start the REST server (in the container) the secret was replaced with certificates - so if you export the restadmin card again with a different name composer card export -c restadmin#trade-network -f restadmin-cert.card you will see that it is a larger file because of the certificates. You should be able to import and use this new .card file.
(If you were using a different card e.g. jdoe - did you run the sed command for this card to correct the addresses?)

Failed to connect docker url with PHP Unit

I can access my site in the browser with the following path: my-dash.docker.localhost:8000. Also, as I found here in order to access the site via POSTMAN I had to add to my host file:
127.0.0.1 my-dash.docker.localhost
I updated my phpunit.xml:
<env name="SIMPLETEST_BASE_URL" value="http://my-dash.docker.localhost:8000"/>
When I run my test I get the following error:
1) Drupal\my_dashboard\Tests\Rest\MyDashboardResourceTest::testPost
GuzzleHttp\Exception\ConnectException: cURL error 7: Failed to connect to my-dash.docker.localhost port 8000: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
/var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:186
/var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:150
I verified that if I add a know url, I don't get this error:
<env name="SIMPLETEST_BASE_URL" value="https://www.google.com/"/>
I found the answer here. Updated phpunit.xml:
<env name="SIMPLETEST_BASE_URL" value="http://nginx"/>
Also in my case, I was using Drupal and had trusted hosts set in my settings.php. I also had to add nginx as a trusted host.

Why am I getting a connection refused error when using the Deadweight gem in rails?

My rake file for deadweight looks like
task :deadweight do
dw = Deadweight.new
dw.stylesheets =["/stylesheets/application.css"]
dw.pages = ["/"]
puts dw.run
end
dw.run is giving following error:
Connection refused - connect(2)
I'm not that familiar with deadweight, but it could be deadweight expects a running server at 0.0.0.0:3000.
From https://github.com/aanand/deadweight :
Running rake deadweight will output all unused rules, one per line.
Note that it looks at http://localhost:3000 by default, so you'll need
to have script/server (or whatever your server command looks like)
running.

How do I point my Heroku OAuth/RoR app to curl-ca-bundle.crt?

I am using Oauth to connect to facebook, and it works fine for local development.
I want to run this on Heroku however, and there I get this error:
2012-06-14T15:50:16+00:00 app[web.1]: Errno::ENOENT (No such file or directory - Certificate file "/opt/local/share/curl/curl-ca-bundle.crt" does not exist!):
2012-06-14T15:50:16+00:00 app[web.1]: app/controllers/sharing_controller.rb:138:in `facebook_callback'
I have configured the SSL endpoint in Heroku but that did not change anything.
I figured it out -
I had to change the Koala cert path parameter:
Old:
Koala.http_service.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt'
New:
Koala.http_service.ca_file = '/usr/lib/ssl/certs/ca-certificates.crt'

Resources