Skip to content

Commit

Permalink
use big-brain to get url from CONVEX_DEPLOY_KEY (#34040)
Browse files Browse the repository at this point in the history
preparation for canonical custom domains

instead of generating urls from deploy keys, use the `/url_for_key` endpoint when deploying with a CONVEX_DEPLOY_KEY to find the url. This allows us to switch from .convex.cloud to a custom domain in a future change.

With this change, the CLI should never try to calculate the url itself, and it shouldn't care what the url looks like. Therefore we should be able to change big-brain apis to return new urls, and the CLI should use them everywhere.

Now that we're using `/url_for_key` in more places, update its docstring. Note it's unusual as an endpoint because it doesn't check authorization with the normal ExtractIdentity, but as long as we validate the deploy key and only return the url, there should be no authz concerns.

GitOrigin-RevId: 453c4444c6285ad2192d25abe948e2a54d13db0c
  • Loading branch information
ldanilek authored and Convex, Inc. committed Feb 4, 2025
1 parent 1478c1d commit 25d433c
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions npm-packages/convex/src/cli/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,19 +397,16 @@ async function fetchDeploymentCredentialsWithinCurrentProjectInner(
ctx,
configuredAdminKey!,
);
let url = await deriveUrlFromAdminKey(ctx, configuredAdminKey!);
// We cannot derive the deployment URL from the deploy key
// when running against local big brain, so use the name to get the URL.
if (process.env.CONVEX_PROVISION_HOST !== undefined) {
url = await bigBrainAPI({
ctx,
method: "POST",
url: "deployment/url_for_key",
data: {
deployKey: configuredAdminKey,
},
});
}
// We cannot derive the deployment URL from the deploy key, because it
// might be a custom domain. Ask big brain for the URL.
const url = await bigBrainAPI({
ctx,
method: "POST",
url: "deployment/url_for_key",
data: {
deployKey: configuredAdminKey,
},
});
const deploymentType = deploymentTypeFromAdminKey(configuredAdminKey!);
return {
adminKey: configuredAdminKey,
Expand Down Expand Up @@ -617,11 +614,3 @@ async function fetchExistingDevDeploymentCredentialsOrCrash(
}
return credentialsAsDevCredentials(credentials);
}

// This returns the the url of the deployment from an admin key in the format
// "tall-forest-1234|1a2b35123541"
// or "prod:tall-forest-1234|1a2b35123541"
async function deriveUrlFromAdminKey(ctx: Context, adminKey: string) {
const deploymentName = await deploymentNameFromAdminKeyOrCrash(ctx, adminKey);
return `https://${deploymentName}.convex.cloud`;
}

0 comments on commit 25d433c

Please sign in to comment.