Skip to content

Commit

Permalink
fix: Use path.join to join paths instead (#65)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Hazmi35 authored Nov 17, 2023
1 parent 00067a6 commit a88eeff
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Structures/REST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AsyncQueue } from '@sapphire/async-queue';
import type { RoutePlannerStatusResponse, LoadTrackResponse, LavalinkTrack, LavalinkSource } from 'lavalink-api-types';
import { LavalinkSourceEnum, LavalinkSearchIdentifierEnum, Routes } from 'lavalink-api-types';
import type { RequestInit } from 'undici';
import { join } from 'path';

export class REST {
public headers: { [key: string]: string } = {};
Expand Down Expand Up @@ -87,7 +88,7 @@ export class REST {
public async get<T>(route: string, init?: RequestInit | undefined): Promise<T> {
await this.queue.wait();
try {
return fetch(new URL(route, this.url), { headers: this.headers, ...init }, FetchResultTypes.JSON);
return fetch(new URL(join(this.url, route)), { headers: this.headers, ...init }, FetchResultTypes.JSON);
} finally {
this.queue.shift();
}
Expand All @@ -96,7 +97,7 @@ export class REST {
public async post<T>(route: string, init?: RequestInit | undefined): Promise<T> {
await this.queue.wait();
try {
return fetch(new URL(route, this.url), { headers: this.headers, method: 'POST', ...init }, FetchResultTypes.JSON);
return fetch(new URL(join(this.url, route)), { headers: this.headers, method: 'POST', ...init }, FetchResultTypes.JSON);
} finally {
this.queue.shift();
}
Expand Down

0 comments on commit a88eeff

Please sign in to comment.