I'm using expressjs with node to create my web app but it's not working as supposed to.
Something really strange happens here, if I go to the first link in the browser, it works as supposed to but if I go to the second link it doesn't get executes the callback and returns null. And as you might see they're identical!
First API code Snippet (First Link):
/**
* GET /workspace/friends/list
* JSON friend list API
*/
app.get('/workspace/friends/list', passportConf.isAuthenticated, function (req, res) {
var userFriends = [];
//console.log(req);
for (var i = 0; i < req.user.friends.length; i++) {
if (req.user.friends[i].verified) {
userFriends.push(req.user.friends[i]);
}
}
res.json(userFriends);
});
Second API code Snippet (Second Link):
/**
* GET /workspace/friends/sentRequests/
* JSON friends requests list API
*/
//TODO: Fix API
app.get('/workspace/friends/sentRequests', passportConf.isAuthenticated, function (req, res) {
var userFriends = [];
//console.log(req);
for (var i = 0; i < req.user.friends.length; i++) {
if (!req.user.friends[i].verified) {
userFriends.push(req.user.friends[i]);
}
}
res.json(userFriends);
});
Note: I must also add that if I uncomment the console.logs in both I get a log from the first but not the second one.
How is this even possible? Has anyone encountered something similar before? And how could I fix it?
Well I figured it out. It's aparrently some sort of Bug that disables one to use long and/or Upper-Case characters in the link, please see this issue I've created (issue #2256).
So when I changed it to the following, it worked fine:
/**
* GET /workspace/friends/sentRequests/
* JSON friends requests list API
*/
//TODO: Fix API
app.get('/workspace/friends/requests/sent', passportConf.isAuthenticated, function (req, res) {
var userFriends = [];
console.log(req);
for (var i = 0; i < req.user.friends.length; i++) {
if (!req.user.friends[i].verified) {
userFriends.push(req.user.friends[i]);
}
}
res.json(userFriends);
});
Note: I haven't figured out where the bug originates.
Update (22/07/2014): What happened is that the boilerplate Skeleton has defined Express's option for case sensitive routing enabled so when I was using and also uses the module express-uncapitalize so when I defined the link with upper-case characters and put that exact same link in the browser it was uncapitalized and express couldn't find that link but uncpitalized (because it's case sensitive).