Reputation: 894
I have a node.js app to call an API. The API works well on the first call, but on the second call, it returns this error message:
404 Not Found: Requested route ('abc.mybluemix.net') does not exist.
Please help review the app.js function:
app.js
app.get('/abc/:provider_id/staffs', function(request, response) {
console.log("Get method invoked.. ")
db = cloudant.use(dbCredentials.dbStaff);
//db = cloudant.use("staffs");
var docList = [];
db.list(function(err, body) {
if (!err) {
var len = body.rows.length;
console.log('total # of docs -> '+len);
if(len == 0) {
// error
} else {
var i = 0;
body.rows.forEach(function(document) {
db.search('allstaff', 'allstaff_index', {q:"provider_id:"+request.params.provider_id}, function(err, doc) {
if (!err) {
if(doc['_attachments']) {
// todo
} else {
var responseDataStaff = createResponseDataStaffs(
doc.rows[i].fields.id,
doc.rows[i].fields.provider_id,
doc.rows[i].fields.firstname,
doc.rows[i].fields.lastname,
doc.rows[i].fields.avatar,
doc.rows[i].fields.email,
doc.rows[i].fields.mobile,
doc.rows[i].fields.address,
doc.rows[i].fields.username,
doc.rows[i].fields.lastlogin,
doc.rows[i].fields.lastlogout
);
}
docList.push(responseDataStaff);
i++;
if(i >= doc.rows.length ) {
response.write(JSON.stringify(docList));
console.log('ending response...');
response.end();
}
} else {
console.log(err);
}
});
});
}
} else {
console.log(err);
}
});
Upvotes: 0
Views: 135
Reputation: 110
The reason you get 404 on the second time is because your app crashed. Debug it locally before you push to Bluemix.
To debug locally you need to have VCAP_SERVICES defined for your app:
Open a terminal and type cf env
Copy the content of VCAP_SERVICES to a local file (e.g. VCAP_SERVICES.json)
Create a new file next to app.js (e.g. debugApp.js) with this content
if(!process.env.VCAP_SERVICES){
process.env.VCAP_SERVICES = JSON.stringify(require("./VCAP_Services.json"));
}
require('./app.js');
Then run node debugApp.js
Upvotes: 3
Reputation: 5637
I'm not sure what you're trying to achieve here but it looks bad
I'm guessing that this isn't what you intended to do.
Upvotes: 2