In restify 1.4 the following statement:
server.get('/:apiversion/:bucket', getList);
used to respond to both http://localhost/v1/records and http://localhost/v1/records/
In version 2.0, this no longer works by default, and in the little bit of trouble shooting I've done so far, I can't even seem to explicitly make it happen:
server.get('/:apiversion/:bucket/', getList);
server.get('/:apiversion/:bucket', getList);
Am I missing something really obvious here, or does restify no longer support trailing slashes on paths?
Yep - b/c some folks wanted this to act differently you now need:
server.pre(restify.pre.sanitizePath());
Somewhere early on.
Added a note to the migration wiki about this: https://github.com/mcavage/node-restify/wiki/1.4-to-2.0-Migration-Tips
Worth adding this tip to the official documentation?
I was also curious if trailing slashes were considered bad practice; the routing doesn't seem to work with them or leave this as a choice for the implementer.
For example using server.get('/app/:foo/, route) returns a 404 when I access /app/123/ but /app/123 works.
I got it working with http://stackoverflow.com/questions/20662656/restify-optional-route-parameters
My issue with that approach is that both routes work. I basically want it to follow my routes exactly and fall to the next route otherwise (so I can then 301 or 404), whether I choose trailing slash or not.
On Apr 30, 2014, at 10:02 PM, Marcello de Sales [email protected] wrote:
I got it working with http://stackoverflow.com/questions/20662656/restify-optional-route-parameters
—
Reply to this email directly or view it on GitHub.
@artzstudio Commend the following line from your code:
// server.pre(restify.pre.sanitizePath());
Hello there!
How do I enable routing with routes having trailing slash? Right now, restify removes trailing slashes from my routes and I don't want that.
Please advise, thank you!
P/S: I'm using restify 4.0.3.
@slavafomin when creating your route, you have an option of passing in your own Regexp:
server.get(/\/foo\//, function(req, res, next) {
// handle the route
});
Hello @micahr , is there a better option? Why Restify can't match routes exactly as they are stated in the configuration? This looks like a serious drawback to me. Using RegExps is overkill and makes code look ugly.
@slavafomin yes, this is feature we'd like to support per #692.
Are there any news?
`server.get('/your/action/:forgetaboutit', handler);
get 'yourserver/your/action/' now works
then you can forget about it.
there is a null value of req.params.forgetaboutit
Most helpful comment
`server.get('/your/action/:forgetaboutit', handler);
get 'yourserver/your/action/' now works
then you can forget about it.
there is a null value of req.params.forgetaboutit