exports.registerApis = function()

in server.js [56:92]


exports.registerApis = function (app) {
  const projectEnv = 'GCLOUD_PROJECT';
  const hubEnv = 'FIREBASE_EMULATOR_HUB';
  const projectId = process.env[projectEnv];
  const hubHost = process.env[hubEnv];
  if (!projectId || !hubHost) {
    throw new Error(
      `Please specify these environment variables: ${projectEnv} ${hubEnv}\n` +
        '(Are you using firebase-tools@>=7.14.0 with `--project your-project`?)'
    );
  }
  // Exposes the host and port of various emulators to facilitate accessing
  // them using client SDKs. For features that involve multiple emulators or
  // hard to accomplish using client SDKs, consider adding an API below.
  app.get(
    '/api/config',
    jsonHandler(async (req) => {
      const hubDiscoveryUrl = new URL(`http://${hubHost}/emulators`);
      hubDiscoveryUrl.hostname = fixHostname(hubDiscoveryUrl.hostname);
      const emulatorsRes = await fetch(hubDiscoveryUrl.toString());
      const emulators = await emulatorsRes.json();

      const json = { projectId, ...emulators };

      if (json.firestore) {
        try {
          const result = await discoverFirestoreWs(json.firestore);
          Object.assign(json.firestore, result);
        } catch (_) {
          // ignored
        }
      }

      return json;
    })
  );
};