mirror of
https://github.com/discordeno/discordeno.git
synced 2026-07-21 13:42:53 +00:00
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:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user