Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class StreamClient<StreamFeedGenerics extends DefaultGenerics = DefaultGe
fayeUrl: string;
group: string;
expireTokens: boolean;
location: string;
location: string | undefined;
fayeClient: Faye.Client<RealTimeMessage<StreamFeedGenerics>> | null;
browser: boolean;
node: boolean;
Expand Down Expand Up @@ -237,7 +237,10 @@ export class StreamClient<StreamFeedGenerics extends DefaultGenerics = DefaultGe
this.subscriptions = {};
this.expireTokens = this.options.expireTokens ? this.options.expireTokens : false;
// which data center to use
this.location = this.options.location as string;
const location = this.options.location as string;
if (location) {
this.location = location;
}
this.baseUrl = this.getBaseUrl();

if (typeof process !== 'undefined') {
Expand Down Expand Up @@ -572,15 +575,20 @@ export class StreamClient<StreamFeedGenerics extends DefaultGenerics = DefaultGe
* @return {axios.AxiosRequestConfig}
*/
enrichKwargs({ method, token, ...kwargs }: AxiosConfig & { method: axios.Method }): axios.AxiosRequestConfig {
const params: Record<string, string> = {
api_key: this.apiKey,
...(kwargs.qs || {}),
};

if (this.group) {
params.location = this.group;
}

return {
method,
url: this.enrichUrl(kwargs.url, kwargs.serviceName),
data: kwargs.body,
params: {
api_key: this.apiKey,
location: this.group,
...(kwargs.qs || {}),
},
params,
headers: {
'X-Stream-Client': this.userAgent(),
'stream-auth-type': 'jwt',
Expand Down