Skip to content

Commit 233ca6d

Browse files
fix: add trailing slash to slackApiUrl if none is provided (#2243)
1 parent 31c60f8 commit 233ca6d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/web-api/src/WebClient.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ describe('WebClient', () => {
5858
const client = new WebClient();
5959
assert.instanceOf(client, WebClient);
6060
});
61+
62+
it('should add a trailing slash to slackApiUrl if missing', () => {
63+
const client = new WebClient(token, { slackApiUrl: 'https://slack.com/api' });
64+
assert.equal(client.slackApiUrl, 'https://slack.com/api/');
65+
});
66+
67+
it('should preserve trailing slash in slackApiUrl if provided', () => {
68+
const client = new WebClient(token, { slackApiUrl: 'https://slack.com/api/' });
69+
assert.equal(client.slackApiUrl, 'https://slack.com/api/');
70+
});
71+
72+
it('should handle custom domains and add trailing slash', () => {
73+
const client = new WebClient(token, { slackApiUrl: 'https://example.com/slack/api' });
74+
assert.equal(client.slackApiUrl, 'https://example.com/slack/api/');
75+
});
6176
});
6277

6378
describe('Methods superclass', () => {
@@ -797,6 +812,15 @@ describe('WebClient', () => {
797812
const client = new WebClient(token, { allowAbsoluteUrls: false });
798813
await client.apiCall('https://example.com/api/method');
799814
});
815+
816+
it('should add a trailing slash to slackApiUrl if missing', async () => {
817+
const alternativeUrl = 'http://12.34.56.78/api'; // No trailing slash here
818+
nock(alternativeUrl)
819+
.post(/api\/method/)
820+
.reply(200, { ok: true });
821+
const client = new WebClient(token, { slackApiUrl: alternativeUrl });
822+
await client.apiCall('method');
823+
});
800824
});
801825

802826
describe('has an option to set request concurrency', () => {

packages/web-api/src/WebClient.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ export class WebClient extends Methods {
286286

287287
this.token = token;
288288
this.slackApiUrl = slackApiUrl;
289+
if (!this.slackApiUrl.endsWith('/')) {
290+
this.slackApiUrl += '/';
291+
}
289292

290293
this.retryConfig = retryConfig;
291294
this.requestQueue = new pQueue({ concurrency: maxRequestConcurrency });
@@ -311,7 +314,7 @@ export class WebClient extends Methods {
311314
this.axios = axios.create({
312315
adapter: adapter ? (config: InternalAxiosRequestConfig) => adapter({ ...config, adapter: undefined }) : undefined,
313316
timeout,
314-
baseURL: slackApiUrl,
317+
baseURL: this.slackApiUrl,
315318
headers: isElectron() ? headers : { 'User-Agent': getUserAgent(), ...headers },
316319
httpAgent: agent,
317320
httpsAgent: agent,

0 commit comments

Comments
 (0)