>
> Hey folks.
>
>
Hi.
> I am trying to work out my way aorund a tiny routing issue I have.
>
> There are three major modules: API, CDN and Main. I want to map them as
> follows:
>
> main => /
> cdn => /cdn
> api => /api
>
> So anything that goes to /api/* is handled by the API part, for instance.
> But all that is called is the main route, and the other two just never get
> a chance.
>
> What would the proper connect setup be to use all three routes? Because I
> just can’t seem to get all three working at the same time…
>
>
Some code would be nice to look at.
Connect as simple http server may have request handlers like so:
var server = require('http').createServer(router);
function router(req, res){
console.log(req.url);
if('/' == req.url){
return main(req, res);
}
if('/cdn' == req.url.slice(0, 4)){
return cdn(req, res);
}
return api(req, res);
}
But for handling middleware stack any such function has 3d argument
var connect = require('connect')
var app = connect()
app.use(mwRouter)
function mwRouter(req, res, next){
var url;
if('/' == req.url){
return main(req, res, next);
}
url = req.url.slice(0, 4);
if('/cdn' == url){
return cdn(req, res, next);
}
if('/api' == url){
return api(req, res, next);
}
return next();// go on with other middlewares
}
`next()` is next handler installed by app.use(function handler(res, req,
next){ }) or this is a shortcut to an error handler if `next(error)` was
actually called.
--
sed 'sh && sed && node.js + olecom = happiness and mirth' << ''
-o--=O`C
#oo'L O
<___=E M
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/cdc1ca19-0717-444c-b9d5-97a98f96fba1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.