functionroute(pathname) { console.log("About to route a request for " + pathname); } exports.route = route;
1 2 3 4 5
var server = require("./url"); var route = require("./route")
server.start(route.route);
随后就能在终端下看到请求的信息
1 2 3 4 5 6 7 8 9
server end Requestfor /12received About to route a request for /12 Requestfor /favicon.icoreceived About to route a request for /favicon.ico Requestfor /myblogreceived About to route a request for /myblog Requestfor /favicon.icoreceived About to route a request for /favicon.ico
3. 路由进行事务处理
之前我们是进行了请求,但是没有进行真正的处理。
1 2 3 4 5 6 7 8 9 10
functionroute(handle, pathname) { console.log("The pathname is " + pathname); if (typeof handle[pathname] == 'function') { handle[pathname](); } else { console.log("No request handle for the " + pathname); } }