开发者

How do I implement real time front end updates using node.js + Ruby on Rails?

开发者 https://www.devze.com 2022-12-30 03:08 出处:网络
What is the best way 开发者_StackOverflow中文版to implement real time updates in ruby on rails using node.js? It would be great to hear either real examples or your thoughts on alternative solutions.I

What is the best way 开发者_StackOverflow中文版to implement real time updates in ruby on rails using node.js? It would be great to hear either real examples or your thoughts on alternative solutions.


I use node for chat with a rails app.

The way I do it is by setting up an nginx front end that proxies my Rails app and my node app.

This allows you to get around the same origin policy and cross communicate.

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 render the html pages from my rails app and communicate with the node app without having to use nasty hacks like JSONP.

A full example is way out of the scope of this answer, but with a good proxy in front you can get them to work happily together.


The way to do it would be with a javascript framework like jquery. Once rails renders the views and passes the html to the client's browser, the javascript can take over to handle updates and request information from node.js since node can handle thousands of concurrent connections.

You can use this method for simple ajax calls or form more complex comet push updates.


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

cause we got the same origin policy in that case, the page (rendered by rails) and the update server (node) must be on the same server & port

I still don't know how to do this.

0

精彩评论

暂无评论...
验证码 换一张
取 消