The way I've seen it done in Express.js (or its URLRouter middleware maybe, 
I'm not quite sure where it is now) is like this:
  app.get('/users/:id(\d+)', function(req, res, id) { ... });
  app.get('/users/:name', function(req, res, username) { ... });
You can just put any regular expression in parenthesis in your route for 
how that token can be matched.  Also allows for regular expressions to 
match ".*" to include slashes, etc.  You could probably even use 
Express's urlrouter/lib/utils.js to build the RegExps for you if you want 
to save some work =).

As for multiple URLs serving the same data, we have found it very useful to 
use the <link rel="cannonical" href="cannonical_url_here"> tag in our 
document head, not for any hand-wavy "SEO" reasons, but for the very 
tangible reason of when we (or users) do a Google search for something in 
one of our pages, there is only a single valid result instead of two nearly 
identical results with different URLs.

  Jimb Esser
  Cloud Party, Inc

On Tuesday, November 5, 2013 7:22:56 AM UTC-8, Alex Kocharin wrote:
>
>
> This is how it's done in express.js:
>
> ```
> app.param('id', function(req, res, next, value, name) {
>     if (value.match(/^\d+$/)) {
>         next()
>     } else {
>         next('route')
>     }
> })
>
> app.get('/users/:id', function(req, res, id) { ... })
> ```
>
> Do something similar. There is no need to add anything to a route, because 
> the name of the param should already imply the type.
>
> If you write "name", it is string, right? Anybody who reads the code will 
> understand that without any explicit "[string]" garbage attached to it.
>
>
> On Monday, November 4, 2013 10:37:28 PM UTC+4, Simon wrote:
>>
>> In my URL routing (express/sinatra-style), I'd like to enable optional 
>> parameter "filters" (like int, hex) while keeping syntax familiar and 
>> simple. The typical syntax for a routing library might look something like:
>>
>>     app.get('/users/:id', function(req, res, id) { ... });
>>
>> I'd like to introduce a syntax for catching only numeric ids so we could 
>> have another route for users by name for instance.
>>
>>     app.get('/users/:id[int]', function(req, res, id) { ... });
>>     app.get('/users/:name', function(req, res, username) { ... });
>>
>> There doesn't seem to be a convention for this, so I've been considering 
>> the following:
>>
>>     '/users/:id[int]'
>>     '/users/:id(int)'
>>     '/users/:id:int'
>>     '/users/:id=int'
>>
>> Any feedback on what's a good way to go that will be simple and obvious 
>> to someone reading the code? If a well-known library is already doing 
>> something like this I'll go with whatever the community is using. Votes 
>> welcome..
>>
>>
>>

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

Reply via email to