Skip to content

Commit a88eeff

Browse files
authored
fix: Use path.join to join paths instead (#65)
* fix: Use path.join to join paths instead This is safer. The previous solution will broke if the url is: http://gateway.local/lavalink, the previous solution will produce http://gateway.local/search for example, and not https://gateway.local/lavalink/search . * fix: lint
1 parent 00067a6 commit a88eeff

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: src/Structures/REST.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AsyncQueue } from '@sapphire/async-queue';
33
import type { RoutePlannerStatusResponse, LoadTrackResponse, LavalinkTrack, LavalinkSource } from 'lavalink-api-types';
44
import { LavalinkSourceEnum, LavalinkSearchIdentifierEnum, Routes } from 'lavalink-api-types';
55
import type { RequestInit } from 'undici';
6+
import { join } from 'path';
67

78
export class REST {
89
public headers: { [key: string]: string } = {};
@@ -87,7 +88,7 @@ export class REST {
8788
public async get<T>(route: string, init?: RequestInit | undefined): Promise<T> {
8889
await this.queue.wait();
8990
try {
90-
return fetch(new URL(route, this.url), { headers: this.headers, ...init }, FetchResultTypes.JSON);
91+
return fetch(new URL(join(this.url, route)), { headers: this.headers, ...init }, FetchResultTypes.JSON);
9192
} finally {
9293
this.queue.shift();
9394
}
@@ -96,7 +97,7 @@ export class REST {
9697
public async post<T>(route: string, init?: RequestInit | undefined): Promise<T> {
9798
await this.queue.wait();
9899
try {
99-
return fetch(new URL(route, this.url), { headers: this.headers, method: 'POST', ...init }, FetchResultTypes.JSON);
100+
return fetch(new URL(join(this.url, route)), { headers: this.headers, method: 'POST', ...init }, FetchResultTypes.JSON);
100101
} finally {
101102
this.queue.shift();
102103
}

0 commit comments

Comments
 (0)