Need help in migrating Hapi application to v20.0.1
kurr2410 opened this issue · comments
Runtime
Node.js
Runtime version
v16.20.2
Module version
^20.0.1
Used with
Hapi application
Any other relevant information
No response
How can we help?
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?
//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, res) => {
return maindb.subcategorymaster.findAll({
where: {'id': req.payload.id}
}).then((result) => {
res(result);
}).catch((DBException) => {
res(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, res) => {
return maindb.subcategorymaster.findAll({
where: {'id': req.payload.id}
}).then((result) => {
return res.response(result);
}).catch((DBException) => {
return res.response(DBException.message);
});
}
};
For major releases we have detailed migration explanations in GitHub issues labelled with "Breaking changes" and "Release notes" labels. Here are the one you'll need to go through considering your starting point and the destination version:
I don't think there is an automated or quick way for you to move from v16 API to v17+ API as the move to async/await kind of impacted the way you write your handlers.
I'll close this issue but we can keep the discussion going if needed.