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

fix: replace fetch with node-fetch to comply with ADR013 #38

Merged
merged 7 commits into from
Mar 15, 2024
Merged

fix: replace fetch with node-fetch to comply with ADR013 #38

merged 7 commits into from
Mar 15, 2024

Conversation

pcgqueiroz
Copy link
Contributor

@pcgqueiroz pcgqueiroz commented Mar 1, 2024

Description

This PR replaces global fetch with node-fetch library as recommended by Backstage on ADR013.

This standardizes on the HTTP package used by the backend plugin and solves issue #37 that prevents HTTP calls to succeed behind a proxy.

Issue number: 37

Type of change

  • New feature (non-breaking change which adds functionality)
  • Fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented
  • Changes generate no new warnings
  • PR title follows conventional commit semantics

If this is a breaking change 👇

  • I have documented the migration process
  • I have implemented necessary warnings (if it can live side by side)

Acknowledgement

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pcgqueiroz pcgqueiroz requested a review from t1agob as a code owner March 1, 2024 09:53
@t1agob t1agob added the under review This issue is being reviewed by the team label Mar 4, 2024
@t1agob t1agob self-assigned this Mar 4, 2024
@t1agob
Copy link
Contributor

t1agob commented Mar 5, 2024

This is failing due to type check validations as response.json() returns type unknown. I'm working on fixing these and will contribute with the necessary changes to make it work.

@t1agob
Copy link
Contributor

t1agob commented Mar 5, 2024

@pcgqueiroz this is now passing all tests and validations. Can you check if this works from behind the proxy? If it makes it easier for you I have published the changes as version 0.4.6-next.0.

@t1agob t1agob changed the base branch from main to next March 5, 2024 13:35
@t1agob t1agob linked an issue Mar 5, 2024 that may be closed by this pull request
@t1agob t1agob changed the title Backstage ADR013 - Use fetch from node-fetch package fix: replace fetch with fetch with node-fetch to comply with ADR013 Mar 5, 2024
@t1agob t1agob changed the title fix: replace fetch with fetch with node-fetch to comply with ADR013 fix: replace fetch with node-fetch to comply with ADR013 Mar 5, 2024
@t1agob t1agob removed the under review This issue is being reviewed by the team label Mar 5, 2024
@t1agob
Copy link
Contributor

t1agob commented Mar 7, 2024

@pcgqueiroz let me know once you have time to test this and if it works or not. Thanks!

@t1agob t1agob changed the base branch from next to main March 8, 2024 15:28
@t1agob t1agob changed the base branch from main to next March 8, 2024 15:29
@t1agob t1agob changed the base branch from next to main March 8, 2024 15:32
pcgqueiroz and others added 5 commits March 8, 2024 15:32
…-fetch

refactor on response.json() after replacing fetch with node-fetch to cast unknown to specific type

Signed-off-by: Tiago Barbosa <tbarbos@hotmail.com>
Signed-off-by: Tiago Barbosa <tbarbos@hotmail.com>
Signed-off-by: Tiago Barbosa <tbarbos@hotmail.com>
remove yarn state from repo as it should be generated on every new build

Signed-off-by: Tiago Barbosa <tbarbos@hotmail.com>
@t1agob t1agob changed the base branch from main to next March 8, 2024 15:35
@pcgqueiroz
Copy link
Contributor Author

@t1agob , I have tested with the package version 0.4.6-next.0 and it did not work. I have the following error:

/backstage/node_modules/@pagerduty/backstage-plugin-backend/dist/index.cjs.js:8
var fetch$1 = require('node-fetch');
              ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /backstage/node_modules/@pagerduty/backstage-plugin-backend/node_modules/node-fetch/src/index.js from /backstage/node_modules/@pagerduty/backstage-plugin-backend/dist/index.cjs.js not supported.
Instead change the require of index.js in /backstage/node_modules/@pagerduty/backstage-plugin-backend/dist/index.cjs.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/backstage/node_modules/@pagerduty/backstage-plugin-backend/dist/index.cjs.js:8:15)
    at @pagerduty/backstage-plugin-backend (/backstage/packages/backend/dist/main.js:577:18)
    at __webpack_require__ (/backstage/packages/backend/dist/main.js:1090:33)
    at fn (/backstage/packages/backend/dist/main.js:1301:21)
    at eval (webpack-internal:///./src/plugins/pagerduty.ts:5:93)
    at ./src/plugins/pagerduty.ts (/backstage/packages/backend/dist/src_plugins_pagerduty_ts.chunk.js:20:1)
    at __webpack_require__ (/backstage/packages/backend/dist/main.js:1090:33)
    at Function.fn (/backstage/packages/backend/dist/main.js:1301:21) {
  code: 'ERR_REQUIRE_ESM'
}

I suspect the error above is related to the node-fetch version 3.3.0. So I have used the source code of the branch and tested with the previous node-fetch version 2.6.7 and everything worked as expected :-)

@t1agob
Copy link
Contributor

t1agob commented Mar 12, 2024

@pcgqueiroz Oh...got it! This is due to the lack of support for ESM for backend modules in Backstage. node-fetch starting on version 3.x is ESM only so we need to downgrade to version 2.x like you suggested.

Can you try it with version 0.4.6-next.2? Thanks!

@pcgqueiroz
Copy link
Contributor Author

Hey @t1agob ! Version 0.4.6-next.2 worked out of the box! Thanks for that, I think it's fine to be merged.

@t1agob t1agob merged commit a2681e5 into PagerDuty:next Mar 15, 2024
1 check passed
@pcgqueiroz pcgqueiroz deleted the patch-1 branch March 15, 2024 10:13
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.

Calls to the backend API hangs forever
2 participants