Skip to content

Firebase Functions Emulator Fails Over Local Network #7538

Closed
@peterfriese

Description

@peterfriese

Step 1: Describe your environment

  • Xcode version: 12.4
  • Firebase SDK version: 7.6.0
  • Installation method: Swift Package Manager
  • Firebase Component: Emulators , Functions

Step 2: Describe the problem

Steps to reproduce:

  1. Create a new Firebase project via the console
  2. Create a new local Firebase project using the CLI
    • Enable Functions and Emulators
    • Enable the Functions and Auth Emulators
    • Use the default ports for setting up the emulators
  3. Implement a simple callable helloWorld function (see below)
  4. Launch the emulators (firebase emulators:start)
  5. Create a new (SwiftUI) project
  6. Download GoogleService-Info.plist and add to project
  7. Enable App Transport Security (allow arbitrary loads)
  8. Initialise the emulators (see Swift code below)
  9. Call helloWorld callable function from Swift (see code below)

Expected behaviour

  • It is possible to call the helloWorld callable function from the iOS app

Observed behaviour

  • GTMSessionFetcher issues error message about http not being in list of allowed insecure schemes:
2021-02-16 16:32:29.570523+0100 FirebaseEmulatorDemo[47823:2419456] Insecure fetch request has a scheme (localhost) not found in fetcher allowedInsecureSchemes (( http )): localhost:5001/peterfriese-friction-emulators/us-central1/helloWorld Error Domain=com.google.GTMSessionFetcher Code=-5 "(null)" UserInfo={NSErrorFailingURLStringKey=localhost:5001/peterfriese-friction-emulators/us-central1/helloWorld} 

Relevant Code:

Callable Function:
exports.helloWorld=functions.https.onCall((data,context)=>{return{message: "Hello World from Firebase"};});

Swift code for initialising emulators and calling the Function

classFirebaseEmulatorDemo:ObservableObject{ lazy varfunctions=Functions.functions()init(){FirebaseApp.configure() // set up emulators Auth.auth().useEmulator(withHost:"localhost", port:9099) functions.useEmulator(withHost:"localhost", port:5001)}func helloWorld(){lethelloWorld= functions.httpsCallable("helloWorld") helloWorld.call(){ result, error iniflet error = error {print(error)}else{iflet message =(result?.data as?[String:Any])?["message"]as?String{print("The function returned: \(message)")}}}}}

Related material

// Override normal security rules if this is a local test.
if (_emulatorOrigin) {
fetcher.allowLocalhostRequest = YES;
fetcher.allowedInsecureSchemes = @[ @"http" ];
}

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    close