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

Include appId in WebConfig #3267

Merged
merged 6 commits into from
Apr 14, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pagination
  • Loading branch information
samtstern committed Apr 14, 2021
commit b67254f5203a1b84ba57ccc0263039ee022ebbff
23 changes: 21 additions & 2 deletions src/fetchWebSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface Site {

interface ListSitesResponse {
sites: Site[];
nextPageToken: string;
}

const apiClient = new Client({ urlPrefix: firebaseApiOrigin, auth: true, apiVersion: "v1beta1" });
Expand Down Expand Up @@ -57,6 +58,24 @@ export function getCachedWebSetup(options: any): WebConfig | undefined {
return allConfigs[projectId];
}

/**
* Recursively list all hosting sites for a given project.
*/
async function listAllSites(projectId: string, nextPageToken?: string): Promise<Site[]> {
const queryParams: Record<string, string> = nextPageToken ? { pageToken: nextPageToken } : {};
const res = await hostingApiClient.get<ListSitesResponse>(`/projects/${projectId}/sites`, {
queryParams,
});

const sites = res.body.sites;
if (res.body.nextPageToken) {
const remainder = await listAllSites(projectId, res.body.nextPageToken);
return [...sites, ...remainder];
}

return sites;
}

/**
* TODO: deprecate this function in favor of `getAppConfig()` in `/src/management/apps.ts`
* @param options CLI options.
Expand All @@ -68,8 +87,8 @@ export async function fetchWebSetup(options: any): Promise<WebConfig> {
// Try to determine the appId from the default Hosting site, if it is linked.
let hostingAppId: string | undefined = undefined;
try {
const sites = await hostingApiClient.get<ListSitesResponse>(`/projects/${projectId}/sites`);
const defaultSite = sites.body.sites.find((s) => s.type === "DEFAULT_SITE");
const sites = await listAllSites(projectId);
const defaultSite = sites.find((s) => s.type === "DEFAULT_SITE");
if (defaultSite && defaultSite.appId) {
hostingAppId = defaultSite.appId;
}
Expand Down