Using hapi and mssql for first time, and I'm struggling to get data from mssql query to the hapi reponse. Here is my code:
const Boom = require('boom');
const sql = require('mssql');
const dbConfig = require('../config/sql');
module.exports = [{
method: 'GET',
path: '/storeInfos',
handler: storeInfos
}
];
function storeInfos(request, h) {
sql.connect(dbConfig).then(() => {
const req = new sql.Request();
req.query('select id, name from StoreInfo').then((data) => {
return h.response(data);
})
.catch((err) => {
reply(Boom.badRequest(err.message, err));
});
})
.catch((err) => {
reply(Boom.badRequest(err.message, err));
});
}
When executing the /storeInfos function, following error is returned "Error: storeInfos method did not return a value, a promise, or throw an error."
I tried to following other examples without any luck and could not find good tutorials either. I'm really stucked with this, some help would be highly appreciated and also some links to some good tutorials. Thanks in advance...