简体   繁体   English

路由如何与Node.js模块一起使用?

[英]How does routing work with Node.js modules?

I would like to see which routes are added by a module using node.js. 我想看看一个模块使用node.js添加了哪些路由。 For instance using Socket.io, I require /socket.io/socket.io.js, yet I do not see this in my public directory or the directory of socket.io: 例如使用Socket.io,我需要/socket.io/socket.io.js,但我没有在我的公共目录或socket.io目录中看到这个:

在此输入图像描述

  <script src="/socket.io/socket.io.js"></script>
    <script>
      var socket = io.connect('http://localhost');
      socket.on('news', function (data) {
        console.log(data);
        socket.emit('my other event', { my: 'data' });
      });
    </script>

The resource loads a file when I inspect the url: 当我检查url时,资源加载文件:

在此输入图像描述

http://localhost:3111/socket.io/socket.io.js

How can I use the rails equivalent of "rake routes"? 我怎样才能使用相当于“rake routes”的轨道?

The URL your browser requests does not have to map to a physical file on your filesystem. 您的浏览器请求的URL不必映射到文件系统上的物理文件。 Socket.IO, for instance, adds scripts to your server's routes via the lib/static.js file ; 例如,Socket.IO通过lib/static.js文件将脚本添加到服务器的路由中; check out the code and you'll see routes for JavaScripts, SWF resources, and more. 查看代码,您将看到JavaScripts,SWF资源等的路由。

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

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