I know few things about url handling in node.js

    *app.param('id', /^\d+$/);
    app.get('/user/:id', function(req, res){
        res.send('user ' + req.params.id);
    });*

Will only accept /user/1, /user/2 ...i.e. with id as integer only

    *app.get('/:type(discussion|page)/:id', ...)  
*
will only accept type with value of discussion or page

   * app.param('range', /^(\d+)\-(\d+)?$/);*
*    app.get('/range/range=:range', function(req, res){*
*    var range = req.params.range;*
*        res.send('from ' + range[1] + ' to ' + range[2]);*
*    });*
will easily handle integer range and directly give us an array without any 
split or parsing and validation.

*Question :   *
    
 1. I have one url which looks for /:path  and path can take values
    listed in a dictionary
    
        var dict={ 
            "a":"You called a", 
            "b": "b is second", 
            "c": "cats are all over internet"
        }
        app.get('/:charc',function(req,res){ 
           res.send(dict[charc]);
        });
    How can I restrict app to accept only a,b,c without putting an if else 
condition.
    currently I am doing  

        if (typeof dict[charc] == 'undefined') res.send(404, 'Sorry, we 
cannot find that!');

 2. Can I call range parameter(from homework part) same way after '?' like  

        app.ge('/range?range=:range',...
    
    with url www.example.com/range?range=123-234

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to