MCPcopy Index your code
hub / github.com/deployd/deployd / nextResource

Function nextResource

lib/router.js:61–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59
60 //TODO: Handle edge case where ctx.next() is called more than once
61 function nextResource() {
62 var resource = resources[i++]
63 , ctx;
64
65 var handler = doh.createHandler({req: req, res: res, server: server});
66 handler.run(function () {
67 process.nextTick(function () {
68 if (resource) {
69 debug('routing %s to %s', req.url, resource.path);
70 ctx = new Context(resource, req, res, server);
71 ctx.router = router;
72
73 // default root to false
74 if(ctx.session) ctx.session.isRoot = req.isRoot || false;
75
76 // external functions
77 var furl = ctx.url.replace('/', '');
78 if(resource.external && resource.external[furl]) {
79 resource.external[furl](ctx.body, ctx, ctx.done);
80 } else {
81 resource.handle(ctx, nextResource);
82 }
83 } else if (next) {
84 next();
85 } else {
86 debug('404 %s', req.url);
87 res.statusCode = 404;
88 error404({message: 'resource not found'}, req, res);
89 }
90 });
91 });
92 }
93
94};
95

Callers 1

router.jsFile · 0.85

Calls 2

debugFunction · 0.85
nextFunction · 0.50

Tested by

no test coverage detected