Route fails (404) with period/dot

310 views
Skip to first unread message

Stacia Hartleben

unread,
Mar 25, 2011, 6:00:03 PM3/25/11
to Express
I am running an older version of Express, perhaps this is the problem
and this has been fixed. However I couldn't find any bug reports about
it so I thought I'd post anyway. I'm running 1.0.1 with node 0.2.6.

I made a very simple server, actually I can post the whole thing here:

var express = require('express')
var app = express.createServer();

app.get('/test/:end_point', function(req, res){

req.params = req.params || [];
var test = req.param('end_point');
res.send(test);
});

app.listen(3000);

Now go to http://localhost:3000/test/abc

It will say "abc"...
but

http://localhost:3000/test/james-t.-kirk

will fail to find the route, with:
Cannot GET /test/james-t.-kirk

Removing the dot fixes the issue. Has this been fixed? Can someone
verify the existence of this problem in the latest version of express?

Laurie Harper

unread,
Mar 26, 2011, 7:18:35 PM3/26/11
to expre...@googlegroups.com
Tried in Express 2.1.0 / Node v0.4.3; seems to work fine there.

> --
> You received this message because you are subscribed to the Google Groups "Express" group.
> To post to this group, send email to expre...@googlegroups.com.
> To unsubscribe from this group, send email to express-js+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/express-js?hl=en.
>

--
Laurie Harper
http://laurie.holoweb.net/

vision media [ Tj Holowaychuk ]

unread,
Mar 27, 2011, 11:07:53 AM3/27/11
to expre...@googlegroups.com
ah yup that is an old connect bug, although there are versions of connect for express 1.x that should have it fixed as well
Tj Holowaychuk
Vision Media
President & Creative Lead

Arunjit Singh

unread,
Mar 29, 2011, 10:24:33 AM3/29/11
to expre...@googlegroups.com, vision media [ Tj Holowaychuk ]
This also happens with '/'..

app.get('/test/:val', ...)

something like
  GET /test/asdf works

but not
  GET /test/a/s/d/f

Have to get around it using a regular expression

  app.get(/^\/test/(.+)/ function(req, res) {
      console.log(req.params[0]);  // "a/s/d/f"
  })

--Arunjit

vision media [ Tj Holowaychuk ]

unread,
Mar 29, 2011, 12:03:11 PM3/29/11
to expre...@googlegroups.com
yes :foo grabs a single segment only, for multiple path segments you can use "*" which consumes
as many as possible, for example "/file/*" for GET /file/pdfs/my.pdf  or "/file/:file(*)" to give it a name
accessible via req.params.file / req.param()

--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.

Arunjit Singh

unread,
Mar 29, 2011, 2:38:41 PM3/29/11
to expre...@googlegroups.com, vision media [ Tj Holowaychuk ]
Thanks! I did not know that

--Arunjit
Reply all
Reply to author
Forward
0 new messages