[关闭]
@WrRan 2016-11-09T16:56:18.000000Z 字数 1829 阅读 778

node.js sails

Router

What does it do?

The core Router in Sails is the main (but not ONLY) player responsible for routing requests.
It is not involved with HTTP, WebSockets, or other internet protocols directly-- instead, it emits
events on the sails object (a Node EventEmitter) when a route should be bound, allowing flexibility
in hooks' implementations.

The core Router includes a latent Express instance which is used only for internal routing of requests,
and is not actually used by any application code in userland-- that's the job of hooks. It may, however,
be used by app-level unit tests, in order to run test suites without having to lift a server and occupy a network port.

Which hooks attach servers / use the Router?

At the time of this writing, the http hook listens for bind events emitted from the core Router
and binds them directly to an external instance of Express.

On the other hand, the sockets hook defers to the core router, emitting a request event whenever
it receives and interprets a new, appropriately-formatted, socket message. The core Router intercepts this
and routes the request using its known middleware bindings. (core middleware, blueprint aka "shadow" routes, and statically configured routes from the routes.js config file in userland)

FAQ

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注