simorgh icon indicating copy to clipboard operation
simorgh copied to clipboard

Remove `node-fetch`

Open amoore108 opened this issue 2 years ago • 0 comments

Reverts bbc/simorgh#11261 and reinstates the original PR: https://github.com/bbc/simorgh/pull/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 https://github.com/bbc/simorgh/pull/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 avatar Jan 08 '24 09:01 amoore108