Skip to content

Commit

Permalink
Merge pull request #388 from GetStream/bug/undef-process
Browse files Browse the repository at this point in the history
fix #386 undef process for angular envs
  • Loading branch information
Amin Mahboubi authored Sep 23, 2020
2 parents ffa5f23 + 46e8d1f commit 1d044c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ export class StreamClient<
this.location = this.options.location as string;
this.baseUrl = this.getBaseUrl();

if (process?.env?.LOCAL_FAYE) this.fayeUrl = 'http://localhost:9999/faye/';
if (process?.env?.STREAM_ANALYTICS_BASE_URL) this.baseAnalyticsUrl = process.env.STREAM_ANALYTICS_BASE_URL;
if (typeof process !== 'undefined' && process.env?.LOCAL_FAYE) this.fayeUrl = 'http://localhost:9999/faye/';
if (typeof process !== 'undefined' && process.env?.STREAM_ANALYTICS_BASE_URL)
this.baseAnalyticsUrl = process.env.STREAM_ANALYTICS_BASE_URL;

this.handlers = {};
this.browser = typeof this.options.browser !== 'undefined' ? this.options.browser : typeof window !== 'undefined';
Expand Down Expand Up @@ -312,9 +313,11 @@ export class StreamClient<
if (this.options.urlOverride && this.options.urlOverride[serviceName]) return this.options.urlOverride[serviceName];

const urlEnvironmentKey = serviceName === 'api' ? 'STREAM_BASE_URL' : `STREAM_${serviceName.toUpperCase()}_URL`;
if (process?.env?.[urlEnvironmentKey]) return process.env[urlEnvironmentKey] as string;
if (typeof process !== 'undefined' && process.env?.[urlEnvironmentKey])
return process.env[urlEnvironmentKey] as string;

if (process?.env?.LOCAL || this.options.local) return `http://localhost:8000/${serviceName}/`;
if ((typeof process !== 'undefined' && process.env?.LOCAL) || this.options.local)
return `http://localhost:8000/${serviceName}/`;

if (this.location) {
const protocol = this.options.protocol || 'https';
Expand Down
2 changes: 1 addition & 1 deletion src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function connect<
ChildReactionType extends UnknownRecord = UnknownRecord,
PersonalizationType extends UnknownRecord = UnknownRecord
>(apiKey: string, apiSecret: string | null, appId?: string, options?: ClientOptions) {
if (typeof process !== 'undefined' && process.env && process.env.STREAM_URL && !apiKey) {
if (typeof process !== 'undefined' && process.env?.STREAM_URL && !apiKey) {
const parts = /https:\/\/(\w+):(\w+)@([\w-]*).*\?app_id=(\d+)/.exec(process.env.STREAM_URL) || [];
apiKey = parts[1];
apiSecret = parts[2];
Expand Down

0 comments on commit 1d044c3

Please sign in to comment.