Reputation: 1
`I need to migrate a hapi.js application from v16.4.3 to ^20.0.1. Since there are major changes made in v17.0.0 including reply() interface upgradation. Is there any optimal way to replace
return reply()
to
return reply.reponse()
in all the handlers?
Node version: v16.20.2 Hapi version: v20.0.1
//working code with version v16.4.3(Hapi)
const addFoo = {
description: 'add foo data',
notes: 'add foo data',
tags: ['api', 'FooCondition'],
validate: {
payload: {
id: joi.number().required(),
},
},
handler: (req, reply) => {
return maindb.subcategorymaster.findAll({
where: {'id': req.payload.id}
}).then((result) => {
reply(result);
}).catch((DBException) => {
reply(DBException.message);
});
}
};
// Wanted to migrate to below code without making manual change at each and every handler.
//working code with version v20.0.1(Hapi)
const addFoo = {
description: 'add foo data',
notes: 'add foo data',
tags: ['api', 'FooCondition'],
validate: {
payload: {
id: joi.number().required(),
},
},
handler: (req, reply) => {
return maindb.subcategorymaster.findAll({
where: {'id': req.payload.id}
}).then((result) => {
return reply.response(result);
}).catch((DBException) => {
return reply.response(DBException.message);
});
}
};
`
Upvotes: 0
Views: 116
Reputation: 1
I tried using middlewares/lifecycle methods but didn't find a way to automate these changes. I also raised this issue at hapi github repo and got the answer as "there isn't an automated or quick way to move from v16 API to v17+ API as the move to async/await kind of impacted the way you write your handlers." Please refer the issue.
Currently we are planning to do manual changes in all the handlers.
You can also refer the v17.0.0 release notes here
Upvotes: 0