feat(rest): strip trailing slash from proxy baseUrl if present in createRestManager() (#5101)

* support docker swarm urls

* Update packages/rest/tests/unit/manager.spec.ts

Co-authored-by: Awesome Stickz <38146668+AwesomeStickz@users.noreply.github.com>

* Update packages/rest/tests/unit/manager.spec.ts

Co-authored-by: Awesome Stickz <38146668+AwesomeStickz@users.noreply.github.com>

* Apply suggestion from @AwesomeStickz

* remove property

* Update packages/rest/src/types.ts

---------

Co-authored-by: Awesome Stickz <38146668+AwesomeStickz@users.noreply.github.com>
This commit is contained in:
Noah
2026-06-24 04:40:42 -06:00
committed by GitHub
parent 678a76fd9c
commit b878b3cb43
3 changed files with 9 additions and 4 deletions
+1 -1
View File
@@ -90,7 +90,7 @@ export const RATE_LIMIT_SCOPE_HEADER = 'x-ratelimit-scope';
export function createRestManager(options: CreateRestManagerOptions): RestManager {
const applicationId = options.applicationId ? BigInt(options.applicationId) : getBotIdFromToken(options.token);
const baseUrl = options.proxy?.baseUrl ?? DISCORD_API_URL;
const baseUrl = (options.proxy?.baseUrl ?? DISCORD_API_URL).replace(/\/$/, '');
// Discord error can get nested a lot, so we use a custom inspect to change the depth to Infinity
const baseErrorPrototype = {
[inspect.custom](_depth: number, options: InspectOptions, _inspect: typeof inspect) {
-1
View File
@@ -169,7 +169,6 @@ export interface CreateRestManagerOptions {
proxy?: {
/**
* The base url to connect to. If you create a proxy rest, that url would go here.
* IT SHOULD NOT END WITH A /
* @default https://discord.com/api
*/
baseUrl: string;
+8 -2
View File
@@ -38,9 +38,15 @@ describe('[rest] manager', () => {
expect(rest.baseUrl).to.be.equal(options.proxy.baseUrl);
});
it('Strips a trailing slash from proxy base urls', () => {
const rest = createRestManager({ ...options, proxy: { ...options.proxy, baseUrl: 'https://localhost:8000/' } });
expect(rest.baseUrl).to.be.equal('https://localhost:8000');
expect(rest.isProxied).to.be.equal(true);
});
it('With an application id', () => {
const subrest = createRestManager({ ...options, applicationId: '130136895395987456' });
expect(subrest.applicationId).to.be.equal(130136895395987456n);
const rest = createRestManager({ ...options, applicationId: '130136895395987456' });
expect(rest.applicationId).to.be.equal(130136895395987456n);
});
});