The async function for getting episodes now send response when the async function is done.
This commit is contained in:
20
server.js
20
server.js
@@ -31,18 +31,18 @@ router.get('/seasoned', function(req, res) {
|
|||||||
var db = new sqlite3.Database(db_path);
|
var db = new sqlite3.Database(db_path);
|
||||||
var returnMsg;
|
var returnMsg;
|
||||||
var id = req.param('id');
|
var id = req.param('id');
|
||||||
|
|
||||||
|
function getEpisode(id, fn){
|
||||||
db.serialize(function() {
|
db.serialize(function() {
|
||||||
db.get("SELECT * FROM stray_eps WHERE id = '" + id + "'", function(err, row) {
|
db.get("SELECT * FROM stray_eps WHERE id = '" + id + "'", function(err, row) {
|
||||||
returnMsg = row;
|
fn(row)
|
||||||
// res.json({message: row});
|
})
|
||||||
// returnList.push(row.original, row.full_path, row.last_name);
|
});
|
||||||
}), console.log(returnMsg);
|
}
|
||||||
}), console.log(returnMsg);
|
|
||||||
// console.log(returnMsg);
|
getEpisode(id, function(episode){
|
||||||
// db.close();
|
res.json({episode}); // this is where you get the return value
|
||||||
db.close();
|
});
|
||||||
res.json({message: toString(returnMsg)});
|
|
||||||
//console.log(returnMsg);
|
|
||||||
});
|
});
|
||||||
// more routes for our API will happen here
|
// more routes for our API will happen here
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user