aantonow
aantonow

Reputation: 23

Ember CLI and Rails: Error proxying to http://localhost:3000

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?

Upvotes: 2

Views: 1249

Answers (2)

Simon
Simon

Reputation: 146

Restart the Rails server with:

rails s --binding 0.0.0.0

then restart the ember server.

Upvotes: 2

Jozef Vaclavik
Jozef Vaclavik

Reputation: 549

There are multiple things you need to watch.

  1. 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'"
    };
    
  2. And you also need to explain Rails app to accept connection outside of the rails app. CORS. Looks for this gem.

Upvotes: 0

Related Questions