Skip to content

Commit 7d0ba34

Browse files
committed
WIP
1 parent 88a8055 commit 7d0ba34

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

packages/data-connect/src/api/DataConnect.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export interface ConnectorConfig {
5858
export interface TransportOptions {
5959
host: string;
6060
sslEnabled?: boolean;
61-
port?: number;
6261
}
6362

6463
const FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR =
@@ -71,11 +70,15 @@ const FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR =
7170
* @internal
7271
*/
7372
export function parseOptions(fullHost: string): TransportOptions {
74-
const [protocol, hostName] = fullHost.split('://');
75-
const isSecure = protocol === 'https';
76-
const [host, portAsString] = hostName.split(':');
77-
const port = Number(portAsString);
78-
return { host, port, sslEnabled: isSecure };
73+
if (fullHost.startsWith('http://') || fullHost.startsWith('https://')) {
74+
const [protocol, host] = fullHost.split('://');
75+
const isSecure = protocol === 'https';
76+
return { host, sslEnabled: isSecure };
77+
}
78+
return {
79+
host: fullHost,
80+
sslEnabled: false
81+
};
7982
}
8083
/**
8184
* DataConnectOptions including project id
@@ -182,7 +185,6 @@ export class DataConnect {
182185
if (this._transportOptions) {
183186
this._transport.useEmulator(
184187
this._transportOptions.host,
185-
this._transportOptions.port,
186188
this._transportOptions.sslEnabled
187189
);
188190
}
@@ -219,7 +221,6 @@ export function areTransportOptionsEqual(
219221
): boolean {
220222
return (
221223
transportOptions1.host === transportOptions2.host &&
222-
transportOptions1.port === transportOptions2.port &&
223224
transportOptions1.sslEnabled === transportOptions2.sslEnabled
224225
);
225226
}
@@ -237,7 +238,8 @@ export function connectDataConnectEmulator(
237238
port?: number,
238239
sslEnabled = false
239240
): void {
240-
dc.enableEmulator({ host, port, sslEnabled });
241+
const hostWithPort = port ? `${host}:${port}` : host;
242+
dc.enableEmulator({ host: hostWithPort, sslEnabled });
241243
}
242244

243245
/**

packages/data-connect/src/network/transport/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface DataConnectTransport {
5151
queryName: string,
5252
body?: U
5353
): Promise<{ data: T; errors: Error[] }>;
54-
useEmulator(host: string, port?: number, sslEnabled?: boolean): void;
54+
useEmulator(host: string, sslEnabled?: boolean): void;
5555
onTokenChanged: (token: string | null) => void;
5656
_setCallerSdkType(callerSdkType: CallerSdkType): void;
5757
}

packages/data-connect/test/unit/dataconnect.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { deleteApp, initializeApp } from '@firebase/app';
1919
import { expect } from 'chai';
2020

21-
import { getDataConnect } from '../../src';
21+
import { getDataConnect, parseOptions } from '../../src';
2222

2323
describe('Data Connect Test', () => {
2424
beforeEach(() => {});
@@ -60,4 +60,22 @@ describe('Data Connect Test', () => {
6060
expect(dc.app.options.projectId).to.eq(projectId);
6161
await deleteApp(customApp);
6262
});
63+
it('should parse env var correctly with http://', async () => {
64+
const parsedHost = parseOptions('http://localhost');
65+
expect(parsedHost.host).to.eq('localhost');
66+
expect(parsedHost.port).to.be.undefined;
67+
expect(parsedHost.sslEnabled).to.be.false;
68+
});
69+
it('should parse env var correctly with port', async () => {
70+
const parsedHost = parseOptions('localhost:8080');
71+
expect(parsedHost.host).to.eq('localhost');
72+
expect(parsedHost.port).to.eq(8080);
73+
expect(parsedHost.sslEnabled).to.be.false;
74+
});
75+
it('should parse env var correctly with https://', async () => {
76+
const parsedHost = parseOptions('https://localhost');
77+
expect(parsedHost.host).to.eq('localhost');
78+
expect(parsedHost.port).to.be.undefined;
79+
expect(parsedHost.sslEnabled).to.be.true;
80+
});
6381
});

0 commit comments

Comments
 (0)