3

Ok, I am new to web dev and here's a stupid question. I have been through a few tutorials for node, express and backbone individually, but I can't seem to wrap my head around how they are integrated. Particularly, consider this use case:

Person X opens the browser, types in a URL and hits enter->Express responds to the request and sends some data back to the browser.

My question is, where does backbone come into the picture here ? I know it's a mvc framework to organize your JS code. But, I can't find a place in this use-case where the server/browser interacts with backbone. Only thing I can think of is that the backbone saving the route and serving the page the next time. But what about the first time ? It would be best if someone could explain to me how the request gets routed from client browser to express/backbone to browser again.

Also, am I correct in assuming response.send() or response.json() will send the result to backbone when model.fetch() is called ? I mean, is there no additional code required ? Being new to web dev, I'm quite not used to the idea of the framework 'taking care' of everything once you send the response back.

EDIT : Here's what I have understood so far. Feel free to correct me if I am wrong. When I access websites like gmail, the server first sends a big html file including backbone.js code in it. The backbone.js code listens for events like clicking on links in the html file and handles them if the links are defined in it routes(routes are always relative to current route, accessing a completely different route sends request to the server). So, if I click compose, my url remains the same because backbone handles the request. However, if I click Maps/News services in the bar above, the server handles the request.

4

1 回答 1

0

主干和 node.js 之间没有特殊的集成。

如果您使用标准主干同步方法,那么您需要做的就是:

  1. 使用 express 中的静态中间件来提供您的静态 html/js/... 文件。

  2. 在 express 中定义符合主干预期的 RESTfule 路由。

当您执行 model.fetch 时,Backbone 确实会进行 http 调用。您可以在 Chome 网络选项卡中查看它将请求发送到的位置,然后以 express 实现该路由。

于 2013-07-14T10:23:50.000 回答