我有一個方法從數據庫獲取查詢結果,並將其中一個結果作爲URL中的參數發送到Hapi.js中的一個路由。無論如何,我可以發送一個JSON對象到我的路線?發送JSON對象到Hapijs路由
路線
{
method: 'GET',
path: '/Account/{Tag}',
config: {
validate: {
query: {
tag: Joi.string()
}
}
},
handler: function(request, reply) {
var tag = encodeURIComponent(request.params.Tag);
reply.view('Account/index', {tag: tag});
}
}
方法/查詢
/**
* Check if Account exists in database, then login
* @param {String} request.query.email
* @param {String} request.query.password
*/
login: function(request, reply) {
connection.query('SELECT email AS email, tag AS tag FROM users WHERE email = ? AND password = ?', [request.query.email, sha256(request.query.password)], function(error, results, fields) {
if (results[0]) {
//reply.(results[0]).created('/Account/' + results[0].tag);
reply.redirect('/Account/' + results[0].tag);
} else {
reply.redirect('/Error');
}
});
},