Skip to content

Commit 1fb1382

Browse files
authored
Fix demo projects + web frameworks with emulators (#6737)
prevent hosting API calls when using JS SDK with frameworks and demo project on emulators
1 parent ca17711 commit 1fb1382

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix demo projects + web frameworks with emulators (#6737)

src/fetchWebSetup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async function listAllSites(projectId: string, nextPageToken?: string): Promise<
8080
/**
8181
* Construct a fake configuration based on the project ID.
8282
*/
83-
function constructDefaultWebSetup(projectId: string): WebConfig {
83+
export function constructDefaultWebSetup(projectId: string): WebConfig {
8484
return {
8585
projectId,
8686
databaseURL: `https://${projectId}.firebaseio.com`,

src/frameworks/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as glob from "glob";
99

1010
import { needProjectId } from "../projectUtils";
1111
import { hostingConfig } from "../hosting/config";
12-
import { listSites } from "../hosting/api";
12+
import { listDemoSites, listSites } from "../hosting/api";
1313
import { getAppConfig, AppPlatform } from "../management/apps";
1414
import { promptOnce } from "../prompt";
1515
import { EmulatorInfo, Emulators, EMULATORS_SUPPORTED_BY_USE_EMULATOR } from "../emulator/types";
@@ -54,6 +54,7 @@ import { isDeepStrictEqual } from "util";
5454
import { resolveProjectPath } from "../projectPath";
5555
import { logger } from "../logger";
5656
import { WebFrameworks } from "./frameworks";
57+
import { constructDefaultWebSetup } from "../fetchWebSetup";
5758

5859
export { WebFrameworks };
5960

@@ -206,12 +207,16 @@ export async function prepareFrameworks(
206207
});
207208
let firebaseConfig = null;
208209
if (usesFirebaseJsSdk) {
209-
const sites = await listSites(project);
210+
const isDemoProject = Constants.isDemoProject(project);
211+
212+
const sites = isDemoProject ? listDemoSites(project) : await listSites(project);
210213
const selectedSite = sites.find((it) => it.name && it.name.split("/").pop() === site);
211214
if (selectedSite) {
212215
const { appId } = selectedSite;
213216
if (appId) {
214-
firebaseConfig = await getAppConfig(appId, AppPlatform.WEB);
217+
firebaseConfig = isDemoProject
218+
? constructDefaultWebSetup(project)
219+
: await getAppConfig(appId, AppPlatform.WEB);
215220
firebaseDefaults ||= {};
216221
firebaseDefaults.config = firebaseConfig;
217222
} else {

src/hosting/api.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,20 @@ export async function listSites(project: string): Promise<Site[]> {
532532
}
533533
}
534534

535+
/**
536+
* Get fake sites object for demo projects running with emulator
537+
*/
538+
export function listDemoSites(projectId: string): Site[] {
539+
return [
540+
{
541+
name: `projects/${projectId}/sites/${projectId}`,
542+
defaultUrl: `https://${projectId}.firebaseapp.com`,
543+
appId: "fake-app-id",
544+
labels: {},
545+
},
546+
];
547+
}
548+
535549
/**
536550
* Get a Hosting site.
537551
* @param project project name or number.

0 commit comments

Comments
 (0)