简体   繁体   English

使用Express.JS运行FIgwheel

[英]Running FIgwheel with Express.JS

Running lein figwheel , from my understanding, starts up a simple static hosting server (via ring) behind the scenes at port 3449. This works on my system. lein figwheel我了解,运行lein figwheellein figwheel启动一个简单的静态托管服务器(通过环网)。这在我的系统上有效。

The problem is that I am hosting my own files via node.js at port 3000 . 问题是我正在通过node.js在端口3000托管我自己的文件。 When I run figwheel, and then start my express.js server, changing my front-end files bizarrely affects both ports the same (ie, updating a file causes both pages to re-render immediately). 当我运行figwheel,然后启动我的express.js服务器时,更改前端文件会奇怪地影响两个端口(即,更新文件会导致两个页面立即重新呈现)。

Question: But how is this possible, if figwheel doesn't know anything about the express.js port 3000 server? 问题:但是,如果figwheel对express.js端口3000服务器一无所知,那怎么可能? And, in any event, is this the best way to use figwheel with my own express server (ie, have two instances running, one default at 3449, and my own port at 3000)? 而且,无论如何,这是否是在我自己的Express服务器上使用figwheel的最佳方法(即,有两个实例在运行,一个实例在3449上运行,而我自己的端口在3000上)?

The page is running javascript built from ClojureScript. 该页面正在运行从ClojureScript构建的javascript。 The build includes figwheel client code. 该版本包括figwheel客户代码。 The code that comes from the figwheel client is opening a websocket connection to a predefined location. 来自Figwheel客户端的代码正在打开到预定位置的Websocket连接。 It doesn't matter where the page is hosted, the javascript will try to connect to the predefined websocket endpoint. 网页的托管位置无关紧要,JavaScript都将尝试连接到预定义的websocket端点。 So if you load the page from the server on 3000, the websocket is still established to the server process you created with lein figwheel . 因此,如果您在3000上从服务器加载页面,则仍会建立websocket到使用lein figwheel创建的服务器进程。 The important bit is that there is the figwheel client code, and the figwheel server. 重要的一点是,这里有figwheel客户代码和figwheel服务器。 The figwheel server is watching the filesystem and telling any websocket connections when the files change. Figwheel服务器正在监视文件系统,并在文件更改时告知任何Websocket连接。 The figwheel client is just connecting to a known websocket and listening for instructions to reload artifacts. figwheel客户端仅连接到已知的Websocket,并正在侦听有关重新加载工件的指令。 So you don't need to use figwheel to serve your static content, as you already discovered. 因此,您不必像已经发现的那样使用Figwheel来提供静态内容。

As for "is this the best way?" 至于“这是最好的方法吗?” Well it is entirely dependent on your goals. 好吧,这完全取决于您的目标。 Certainly it works great, so if there is some advantage to running both, go for it! 当然,它可以很好地运行,所以如果两者都运行有优势,那就去吧! On the other hand, why run an express server if you don't need it? 另一方面,如果不需要快递服务器,为什么还要运行它呢?

One circumstance where running 2 servers is advantageous is when you are relying on server side functionality that does not fit well with using figwheel as the host. 运行2台服务器比较有优势的一种情况是,您依赖于服务器端功能,而该功能与使用Figwheel作为主机不太匹配。 This could be due to deployment (maybe you don't want to use a ring handler as your primary server), or a technical limitation (I like to use httpkit for websockets, and afaik there isn't a good way of running these from a ring handler). 这可能是由于部署(也许您不想使用环形处理程序作为主服务器),或者是技术限制(我喜欢将httpkit用于websocket,而afaik)没有一种从铃声处理程序)。 But, as you pointed out, you can still use figwheel for fast development reloading even if you aren't using it to serve files or services. 但是,正如您指出的那样,即使您不使用figwheel来进行文件的重新加载,也可以使用它进行快速的重新加载。

Obviously the figwheel server needs to be watching the right files though, so make sure figwheel is configured to observe the right directories. 显然,Figwheel服务器需要监视正确的文件,因此,请确保figwheel配置为观察正确的目录。

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

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