FAQ
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
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 nodejs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Gaurav Meena at Apr 8, 2013 at 11:41 am
    sorry.
    it should be posted in
    https://groups.google.com/forum/?fromgroups#!forum/express-js group

    --
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    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 nodejs+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedApr 8, '13 at 11:39a
activeApr 8, '13 at 11:41a
posts2
users1
websitenodejs.org
irc#node.js

1 user in discussion

Gaurav Meena: 2 posts

People

Translate

site design / logo © 2022 Grokbase