Skip to content

Commit b2cbca5

Browse files
fix: Split settings.host into servicePath and port (#684)
1 parent 5ba0e5c commit b2cbca5

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

dev/src/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ export class Firestore {
315315
* support {@link https://cloud.google.com/docs/authentication Application
316316
* Default Credentials}. If your credentials are stored in a JSON file, you
317317
* can specify a `keyFilename` instead.
318+
* @param {string=} settings.host The host to connect to.
319+
* @param {boolean=} settings.ssl Whether to use SSL when connecting.
318320
* @param {boolean=} settings.timestampsInSnapshots Specifies whether to use
319321
* `Timestamp` objects for timestamp fields in `DocumentSnapshot`s. This is
320322
* enabled by default and should not be disabled.
@@ -346,13 +348,8 @@ export class Firestore {
346348
process.env.FIRESTORE_EMULATOR_HOST
347349
);
348350

349-
const url = new URL('http://' + process.env.FIRESTORE_EMULATOR_HOST);
350-
const host = url.hostname;
351-
const port = url.port !== '' ? Number(url.port) : undefined;
352-
353351
this.validateAndApplySettings({
354-
host,
355-
port,
352+
host: process.env.FIRESTORE_EMULATOR_HOST,
356353
ssl: false,
357354
customHeaders: {
358355
Authorization: 'Bearer owner',
@@ -457,7 +454,12 @@ export class Firestore {
457454
'Cannot set both "settings.host" and "settings.apiEndpoint".'
458455
);
459456
}
460-
settings.servicePath = settings.host;
457+
458+
const url = new URL(`http://${settings.host}`);
459+
settings.servicePath = url.hostname;
460+
if (url.port !== '' && settings.port === undefined) {
461+
settings.port = Number(url.port);
462+
}
461463
}
462464

463465
if (settings.ssl !== undefined) {

dev/src/util.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
/** A Promise implementation that supports deferred resolution. */
17+
/**
18+
* A Promise implementation that supports deferred resolution.
19+
* @private
20+
*/
1821
export class Deferred<R> {
1922
promise: Promise<R>;
2023
resolve: (value?: R | Promise<R>) => void = () => {};

0 commit comments

Comments
 (0)