Skip to content

Commit

Permalink
Update Hapi to v21 (#650)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4039

Phew! Somehow when looking into why there were errors during an import process we've ended up needing to upgrade Hapi!

In order to better debug issues with the NALD import process we wanted to add a new POST endpoint that would allow us to trigger it manually. But when we did we saw the request logged but nothing was actually firing. The handler would not be called and the request would not disconnect leaving Postman whirring away.

We quickly spotted `GET` requests were fine it was just `POST` failing. Hmm 🤔

Some Googling later and we found we were not alone

- [POST request not completing on postman](https://stackoverflow.com/a/72642389/6117745)
- [Hapi js server does not respond to my post route](https://www.reddit.com/r/node/comments/syq6t0/hapi_js_server_does_not_respond_to_my_post_route/?utm_source=share&utm_medium=web2x&context=3)
- [request disconnect event does not trigger for certain HTTP methods under node v16](hapijs/hapi#4315)

It seems the root cause is running Hapi on Node v16 which we are doing in our local dev environment. In our AWS environments, we're running v14 but we intend to upgrade as soon as SROC supplementary billing is shipped.

So, we know this project is fine in AWS running v14 which concurs with those posts. But we also know apps like [water-abstraction-service](https://github.com/DEFRA/water-abstraction-service) are handling `POST` requests fine in our local dev environment. The difference is the version of Hapi; they are running v21 but the import service is running v18.

This change updates Hapi to v21 (and anything else needed along the way) in order to resolve this issue and get the project ready for upgrading all our environments to v16.

The upgrade from version 18->19 introduces a breaking change as per the v19 release notes hapijs/hapi#4017 - _"No joi schema compiler is loaded by default and must be explicitly loaded"_. 

This breaking change produces the error `error: AssertError: Cannot set uncompiled validation rules without configuring a validator` which is fixed by explicitly loading joi.

**Notes**

- Bump `@hapi/hapi` 3 major versions
- Fix issues caused by updating `@hapi/hapi` (The upgrade from version 18->19 introduces a breaking change "No joi schema compiler is loaded by default and must be explicitly loaded". This commit fixes that issue as per the v19 release notes: hapijs/hapi#4017)

---------

Co-authored-by: Jason Claxton <30830544+Jozzey@users.noreply.github.com>
Co-authored-by: Jason Claxton <jason.claxton@defra.gov.uk>
  • Loading branch information
3 people committed Jun 8, 2023
1 parent 4e095fb commit c1ae21c
Show file tree
Hide file tree
Showing 4 changed files with 395 additions and 383 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const start = async function () {
try {
await server.register(plugins)
await server.register(HapiPinoPlugin())
server.validator(require('@hapi/joi'))
configureServerAuthStrategy(server)
server.route(routes)

Expand Down
Loading

0 comments on commit c1ae21c

Please sign in to comment.