How does the Express framework or node.js automatically serve javascript files?
I added this line to my index.jade file:
script(src="/socket.io/socket.io.js")
And somehow it automagically knew how to serve 开发者_Python百科that Javascript file to my client. How does that work?
Socket.io adds a request handler to the server. See:
https://github.com/learnboost/socket.io/blob/master/lib/manager.js#L90
The handler deals with any requests that begin with /socket.io and handles them (e.g. serving up the socket.io.js file from wherever the module is installed)
精彩评论