The order matters when you call 'app.use(..)'.
Try changing the order of your calls so that app.use('/', ...) is the last
one instead of the first one.

Kris

On Thu, Jan 22, 2015 at 4:53 PM, Kevin Ingwersen (Ingwie Phoenix) <
[email protected]> wrote:

> Right, should’ve shown the code beforehand. Here goes:
>
> - The entry code: http://git.ingwie.me/ingwie/bird3/blob/master/app.js
> - The actual handler code:
> http://git.ingwie.me/ingwie/bird3/blob/master/lib/request_handler.js
>
> Please note that I have to use vhost for this case. For now, that seems to
> somehow work. But. If I pass a new connect instance to the api_handler.js
> file, it will never be reached. So I think my routing is a little f****d up…
>
> When I tried to turn this whole thing into a clustered aproach (in hopes
> to increase speed, which seemed to not have been the case…) I had tried to
> make the orutes without the vhost module at all, which then looked like:
>
> var connect = require("connect"),
>     app = connect(),
>     main = connect(),
>     api = connect(),
>     cdn = connect();
>
> app.use(connectLogger());
> app.use(responsetime());
> app.use(compress());
>
> // Now comes
> app.use("/", main);
> app.use("/cdn", cdn);
> app.use("/api", api);
>
> // The files were re-written by then.
> require("lib/request_handler")(main);
> require("lib/cdn_handler")(cdn);
> require("lib/api_handler")(api);
>
> But that resulted in a total mess. My main site loaded, but only the /
> route got hit - none of the others were! Even when I moved it to the
> bottom, same result…
>
> Am 22.01.2015 um 08:25 schrieb Oleg Verych <[email protected]>:
>
> 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
> <https://groups.google.com/d/msgid/nodejs/cdc1ca19-0717-444c-b9d5-97a98f96fba1%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> 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/B06AF7FF-8CC0-4B93-B65A-D8779329C6E6%40googlemail.com
> <https://groups.google.com/d/msgid/nodejs/B06AF7FF-8CC0-4B93-B65A-D8779329C6E6%40googlemail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAL6D%2BG-x9Z8idWQtgebne1PHVOLPHVEv8z7V2B%3DeutNa5jZhcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to