简体   繁体   English

ruby http带有观察模式的静态Web服务器?

[英]ruby http static web server with watch mode?

Is there a ruby http server (like httpd) for static web sites with a watch mode that updates the browser? 是否有用于监视网站的静态Web站点的ruby http服务器(如httpd)来更新浏览器?

Currently if the website is running in httpd I have to refresh the browser after file changes. 目前,如果网站运行在httpd中,则文件更改后我必须刷新浏览器。

Ruby on Rails has ActionCable which uses websockets to keep a browser up to date using a publish/subscribe method. Ruby on Rails的ActionCable使用websocket通过发布/订阅方法使浏览器保持最新。

Edit : Faye-websocket is a websocket implementation that doesn't require any framework, just a Rack-compliant web server. 编辑Faye-websocket是一个websocket的实现,不需要任何框架,只需一个符合Rack的Web服务器即可。

Depending on your needs there may be pre-built application available. 根据您的需求,可能会提供预构建的应用程序。 For example, if you want a dashboard with widgets that update live, you can use Smashing . 例如,如果您想要一个带有实时更新的小部件的仪表板,则可以使用Smashing

In addition to Mark's answer, iodine is a Ruby HTTP and Websocket server written in C. 除了Mark的回答, iodine是用C编写的Ruby HTTP和Websocket服务器。

It sports a basic static file service as well as native support for Websocket connections (using a websocket callback object). 它提供了基本的静态文件服务以及对Websocket连接的本地支持(使用websocket回调对象)。

The static file service doesn't even require a Ruby application. 静态文件服务甚至不需要Ruby应用程序。 ie: 即:

 $  iodine -www ./

Iodine also supports pub/sub (with or without Redis) out of the box, moving a lot of the workload out of the Ruby layer and into the C engine. Iodine还支持开箱即用的pub / sub(带有或不带有Redis),将大量工作负载从Ruby层移出并移入C引擎。

It's possible to run iodine in single threaded mode (due to it's evented design), though the current default will use as many threads and processes as there are cores on the machine (which prefers concurrency over performance). 可以在单线程模式下运行iodine(由于事件设计而定),尽管当前的默认值将使用与机器上存在的内核一样多的线程和进程(相比于性能,它更喜欢并发)。

When using Rails, iodine can be used instead of ActionCable by catching Websocket connections using middleware (either custom made or, for example, the Plezi gem ). 使用Rails时,通过使用中间件(定制的或例如Plezi gem的 )捕获Websocket连接,可以使用碘代替ActionCable。

I'm biased, being the author, but I think it's an easy solution to implement and my tests show that it's significantly more performant. 作为作者,我有偏见,但我认为这是一个易于实施的解决方案,而我的测试表明,它的性能明显更高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM