Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove node-fetch #11266

Merged
merged 137 commits into from
Oct 24, 2024
Merged

Remove node-fetch #11266

merged 137 commits into from
Oct 24, 2024

Conversation

amoore108
Copy link
Contributor

@amoore108 amoore108 commented Jan 8, 2024

Reverts #11261 and reinstates the original PR: #11122

Description from original PR:

Overall changes

Removes node-fetch and isomorphic-fetch in favour of using Node 18+ built-in fetch mechanism, provided by undici. Removes the need to do #9611

undici has been added as a dependency as we need its Agent constructor to use our custom certs to authenticate requests.

This aligns the Express and Next.js app to use the same fetch mechanism across both apps, and removes the need to keep node-fetch updated through its transition to ESM.

Code changes

  • Remove node-fetch and isomorphic-fetch and the instances these libraries were imported
  • Consolidate the getAgent function across the Express and Next.js apps
  • Mock Agent and getAgent in tests
  • Refactors the Live page fetch to be more inline with other fetchers that use fetchDataFromBFF

Testing

  1. Pull down this branch locally
  2. Run yarn to install the new dependencies
  3. Run yarn dev
  4. Visit a url with the renderer_env=live flag to ensure it fetches Live data with the certs
  5. Confirm the page loads as expected
  6. Repeat the steps for the Next.js app

@amoore108 amoore108 self-assigned this Jan 8, 2024
@amoore108 amoore108 changed the title [DNM] Revert "Revert "Remove node-fetch"" [DNM] Remove node-fetch Feb 9, 2024
@amoore108 amoore108 marked this pull request as ready for review October 23, 2024 14:09
const BFF_IS_LOCAL =
process.env.JEST_WORKER_ID === undefined &&
process?.env?.BFF_PATH?.includes('localhost:3210');
const BFF_IS_LOCAL = process?.env?.BFF_PATH?.includes('localhost:3210');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this now be removed? BFF_IS_LOCAL is used in an if statement below to determine whether to add optional headers or not, but wondering if we could use certsRequired instead?

Copy link
Contributor Author

@amoore108 amoore108 Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the logic now to try and make it a bit simpler, inline with your suggestion. a32bff8

It has changed the value of the headers when running locally, but I tested this with the BFF running on the Test env and with the BFF running locally as well and it seems fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more commits to get it working, but think its a bit better? Not sure of the need of the accept header locally, so its removed.

@amoore108 amoore108 merged commit df4043e into latest Oct 24, 2024
11 checks passed
@amoore108 amoore108 deleted the revert-11261-revert-11122-remove-nodefetch branch October 24, 2024 07:59
amoore108 added a commit that referenced this pull request Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants