-
Notifications
You must be signed in to change notification settings - Fork 64
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
fix: use staging url for extensions on staging #6140
Conversation
}: 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/` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
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/` |
There was a problem hiding this comment.
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.
- 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?
- 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)
There was a problem hiding this comment.
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
packages/config/src/api/site_info.ts
Outdated
|
||
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 ` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
packages/config/src/api/site_info.ts
Outdated
const extensionApiBaseUrl = | ||
netlifyApiHost === 'api.netlify.com' ? 'https://api.netlifysdk.com' : `https://api-staging.netlifysdk.com ` |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
const extensionApiBaseUrl = | ||
netlifyApiHost === 'api.netlify.com' ? 'https://api.netlifysdk.com/' : `https://api-staging.netlifysdk.com/` |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:spiderman-pointing:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% agreed!
There was a problem hiding this comment.
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
🎉 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:
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.
your code follows our style guide and passes our tests.
A picture of a cute animal (not mandatory, but encouraged)