(options: any)
| 96 | * @return web app configuration. |
| 97 | */ |
| 98 | export async function fetchWebSetup(options: any): Promise<WebConfig> { |
| 99 | const projectId = needProjectId(options); |
| 100 | |
| 101 | // When using the emulators with a fake project ID, use a fake web config |
| 102 | if (Constants.isDemoProject(projectId)) { |
| 103 | return constructDefaultWebSetup(projectId); |
| 104 | } |
| 105 | |
| 106 | // Try to determine the appId from the default Hosting site, if it is linked. |
| 107 | let hostingAppId: string | undefined = undefined; |
| 108 | try { |
| 109 | const sites = await listAllSites(projectId); |
| 110 | const defaultSite = sites.find((s) => s.type === "DEFAULT_SITE"); |
| 111 | if (defaultSite && defaultSite.appId) { |
| 112 | hostingAppId = defaultSite.appId; |
| 113 | } |
| 114 | } catch (e: any) { |
| 115 | logger.debug("Failed to list hosting sites"); |
| 116 | logger.debug(e); |
| 117 | } |
| 118 | |
| 119 | // Get the web app config for the appId, or use the '-' special value if the appId is not known |
| 120 | const appId = hostingAppId || "-"; |
| 121 | const res = await apiClient.get<WebConfig>(`/projects/${projectId}/webApps/${appId}/config`); |
| 122 | const config = res.body; |
| 123 | |
| 124 | if (!config.appId && hostingAppId) { |
| 125 | config.appId = hostingAppId; |
| 126 | } |
| 127 | |
| 128 | setCachedWebSetup(config.projectId, config); |
| 129 | return config; |
| 130 | } |
no test coverage detected
searching dependent graphs…