How to implement real-time interface updates using node.js + Ruby on Rails?

What is the best way to implement real-time updates in ruby ​​on rails using node.js? It would be great to hear real examples or your thoughts on alternative solutions.

+4
source share
3 answers

I am using node to communicate with the rails application.

How do I do this by creating the front end of nginx, which proxies my Rails application and my node application.

This circumvents the same origin policy and cross-communicates.

Here is a snippet of my nginx.conf

location /chat_service { rewrite /chat_service/(.+) /$1 break; proxy_pass http://localhost:9000/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; } 

This means that I can display html pages from my rails application and communicate with the node application without using nasty hacks like JSONP.

A complete example is getting out of the scope of this answer, but with a good proxy server you can get them to work together.

+4
source

The way to do this would be with a javascript framework like jquery. After the rails display the views and pass the html to the client browser, javascript can take over the processing and request information from node.js, since node can handle thousands of simultaneous connections.

You can use this method for simple ajax calls or create more sophisticated comet push updates.

-1
source

It's not that simple, I'm afraid ...

because we got the same origin policy in this case the page (displayed by rails) and the update server (node) must be on the same server and port

I still don’t know how to do this.

-1
source

Source: https://habr.com/ru/post/1309803/


All Articles