Skip to content

fix: use staging url for extensions on staging #6140

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

Merged
merged 5 commits into from
Mar 18, 2025

Conversation

khendrikse
Copy link
Contributor

@khendrikse khendrikse commented Mar 18, 2025

🎉 Thanks for submitting a pull request! 🎉

Summary

This ensures that we align our extension API with the right environment.

We use the netlify api host to check if we are on production or staging. This determines the extension api url.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures
    we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
    something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures
    your code follows our style guide and passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@khendrikse khendrikse requested a review from a team as a code owner March 18, 2025 12:41
lemusthelroy
lemusthelroy previously approved these changes Mar 18, 2025
serhalp
serhalp previously approved these changes Mar 18, 2025
}: GetAvailableIntegrationsOpts): Promise<AvailableIntegration[]> {
if (offline) {
return []
}
const { host } = testOpts
const baseUrl = new URL(host ? `http://${host}/` : `https://api.netlifysdk.com/`)
const extensionApiBaseUrl =
netlifyApiHost === 'api.netlify.com' ? 'https://api.netlifysdk.com/' : `https://api-staging.netlifysdk.com/`
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
netlifyApiHost === 'api.netlify.com' ? 'https://api.netlifysdk.com/' : `https://api-staging.netlifysdk.com/`
netlifyApiHost === 'api.netlify.com' ? PRODUCTION_SDK_API_HOST : STAGING_SDK_API_HOST

}: GetAvailableIntegrationsOpts): Promise<AvailableIntegration[]> {
if (offline) {
return []
}
const { host } = testOpts
const baseUrl = new URL(host ? `http://${host}/` : `https://api.netlifysdk.com/`)
const extensionApiBaseUrl =
netlifyApiHost === 'api.netlify.com' ? 'https://api.netlifysdk.com/' : `https://api-staging.netlifysdk.com/`
Copy link
Contributor

@serhalp serhalp Mar 18, 2025

Choose a reason for hiding this comment

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

I'm not familiar with how this is all set up currently, but this mapping seems a bit brittle.

  1. Would it be a big lift to map all prod/staging/etc. hosts from a single 'mode' or 'env' rather than mapping one set from another?
  2. The assumption that any host that doesn't precisely match api.netlify.com should quietly map to the staging SDK API host seems brittle as well. Could we explicitly map prod -> prod and staging -> staging and throw otherwise? (or at least log an error or something)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100%, I want to try it this way first and then see if I can let buildbot/cli pass in the right url depending on the environment


const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`)
const extensionApiBaseUrl =
netlifyApiHost === 'api.netlify.com' ? 'https://api.netlifysdk.com' : `https://api-staging.netlifysdk.com `
Copy link
Contributor

Choose a reason for hiding this comment

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

could we extract these constants somewhere instead of duplicating them in two files? presumably they could just be exported from src/api/integrations.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved them to a top level for now

Comment on lines 139 to 140
const extensionApiBaseUrl =
netlifyApiHost === 'api.netlify.com' ? 'https://api.netlifysdk.com' : `https://api-staging.netlifysdk.com `
Copy link
Contributor

Choose a reason for hiding this comment

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

could we add some basic test coverage for this? It seems pretty critical!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really want to do that but the test setup is making this quite a struggle right now.

Comment on lines 18 to 19
const extensionApiBaseUrl =
netlifyApiHost === 'api.netlify.com' ? 'https://api.netlifysdk.com/' : `https://api-staging.netlifysdk.com/`
Copy link
Contributor

Choose a reason for hiding this comment

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

could we add some basic test coverage for this? It seems pretty critical!

const baseUrl = new URL(host ? `http://${host}/` : `https://api.netlifysdk.com/`)
const extensionApiBaseUrl =
netlifyApiHost === 'api.netlify.com' ? 'https://api.netlifysdk.com/' : `https://api-staging.netlifysdk.com/`
const baseUrl = new URL(host ? `http://${host}/` : extensionApiBaseUrl)
Copy link
Member

Choose a reason for hiding this comment

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

Do we ever want to connect to the API over HTTP?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering the same thing, but I think the assumption here is that the passed in testOpts.host is a local server for testing, so it uses http.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean because of the http://${host}/?

}: GetAvailableIntegrationsOpts): Promise<AvailableIntegration[]> {
if (offline) {
return []
}
const { host } = testOpts
const baseUrl = new URL(host ? `http://${host}/` : `https://api.netlifysdk.com/`)
const extensionApiBaseUrl =
Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine as a quick fix, but long-term I don't think we should be doing this. If we ever change the API URL, or introduce a variation of it, we'll start to pick the staging SDK endpoint and things will start failing silently in unexpected ways.

We should make it so that whoever passes the API URL also passes the corresponding SDK URL.

Copy link
Contributor

Choose a reason for hiding this comment

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

:spiderman-pointing:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% agreed!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to try it this way first and then see if I can let buildbot/cli pass in the right url depending on the environment. This truly is a quick fix

@khendrikse khendrikse dismissed stale reviews from serhalp and lemusthelroy via 92e23e0 March 18, 2025 13:30
@khendrikse khendrikse requested a review from DanielSLew March 18, 2025 13:45
@khendrikse khendrikse merged commit 978b3c3 into main Mar 18, 2025
31 of 32 checks passed
@khendrikse khendrikse deleted the cpla-2603/use-staging-for-fetching-extensions branch March 18, 2025 14:21
This was referenced Mar 18, 2025
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.

5 participants