resolveFunctionUrl static method

  1. @visibleForTesting
String resolveFunctionUrl({
  1. required String functionName,
  2. required String productionUrl,
  3. required bool isRelease,
  4. required bool usesEmulators,
  5. String host = '127.0.0.1',
  6. int port = 5001,
  7. String projectId = 'demo-emxi-local',
  8. String region = 'us-central1',
})

Implementation

@visibleForTesting
static String resolveFunctionUrl({
  required String functionName,
  required String productionUrl,
  required bool isRelease,
  required bool usesEmulators,
  String host = '127.0.0.1',
  int port = 5001,
  String projectId = 'demo-emxi-local',
  String region = 'us-central1',
}) {
  if (isRelease) return productionUrl;

  if (!usesEmulators) {
    throw StateError(
      'Cloud Functions productivas bloqueadas en debug/profile. '
      'Inicia Firebase Functions Emulator y usa '
      'USE_FIREBASE_EMULATORS=true.',
    );
  }

  if (functionName.isEmpty ||
      host.isEmpty ||
      port <= 0 ||
      projectId.isEmpty ||
      region.isEmpty) {
    throw StateError(
      'Configuracion invalida del Functions Emulator para "$functionName".',
    );
  }

  return Uri(
    scheme: 'http',
    host: host,
    port: port,
    pathSegments: [projectId, region, functionName],
  ).toString();
}