diff --git a/src/client.ts b/src/client.ts index 42d694be..da51c6e0 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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'; @@ -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'; diff --git a/src/connect.ts b/src/connect.ts index 7cb0bfc2..99d9279b 100644 --- a/src/connect.ts +++ b/src/connect.ts @@ -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];