Skip to content

Commit

Permalink
feat(functions): Add regionOrCustomDomain option to useEmulator. (#766)
Browse files Browse the repository at this point in the history
* fix(functions): Add regionOrCustomDomain option to useEmulator.

* fix useEmulator for specific region

Introduced a new property `regionOrCustomDomain` to the `UseEmulatorOptions` interface to enable specifying either a region or a custom domain for callable Firebase functions. This change facilitates greater flexibility in configuring the functions emulator based on deployment preferences. Updated related documentation to reflect these changes for clarity.

* Update .changeset/cuddly-baboons-add.md [skip ci]

---------

Co-authored-by: Robin Genz <[email protected]>
  • Loading branch information
dimer47 and robingenz authored Dec 9, 2024
1 parent 069edf3 commit 258ea28
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-baboons-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capacitor-firebase/functions': minor
---

feat(functions): add `regionOrCustomDomain` option to `UseEmulatorOptions`
9 changes: 5 additions & 4 deletions packages/functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,11 @@ On Android, the cleartext traffic must be allowed. On the Capacitor configuratio

#### UseEmulatorOptions

| Prop | Type | Description | Default | Since |
| ---------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | ----- |
| **`host`** | <code>string</code> | The emulator host without any port or scheme. Note when using a Android Emulator device: 10.0.2.2 is the special IP address to connect to the 'localhost' of the host computer. | | 6.1.0 |
| **`port`** | <code>number</code> | The emulator port. | <code>5001</code> | 6.1.0 |
| Prop | Type | Description | Default | Since |
| -------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | ----- |
| **`host`** | <code>string</code> | The emulator host without any port or scheme. Note when using a Android Emulator device: 10.0.2.2 is the special IP address to connect to the 'localhost' of the host computer. | | 6.1.0 |
| **`port`** | <code>number</code> | The emulator port. | <code>5001</code> | 6.1.0 |
| **`regionOrCustomDomain`** | <code>string</code> | one of: a) The region the callable functions are located in (ex: us-central1) b) A custom domain hosting the callable functions (ex: https://mydomain.com) | | |


### Type Aliases
Expand Down
7 changes: 7 additions & 0 deletions packages/functions/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,11 @@ export interface UseEmulatorOptions {
* @example 5001
*/
port?: number;
/**
* The region the callable functions are located in or a custom domain hosting the callable functions.
*
* @example 'us-central1'
* @example 'https://mydomain.com'
*/
regionOrCustomDomain?: string;
}
2 changes: 1 addition & 1 deletion packages/functions/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class FirebaseFunctionsWeb
}

public async useEmulator(options: UseEmulatorOptions): Promise<void> {
const functions = getFunctions();
const functions = getFunctions(undefined, options.regionOrCustomDomain);
const port = options.port || 5001;
connectFunctionsEmulator(functions, options.host, port);
}
Expand Down

0 comments on commit 258ea28

Please sign in to comment.