mirror of
https://codeberg.org/reflect/reflect-client-js.git
synced 2025-09-14 09:13:41 +02:00
fix: tailing slash for domain name (#4)
This commit is contained in:
parent
278868984d
commit
2be18c2a33
1 changed files with 5 additions and 1 deletions
|
@ -9,7 +9,8 @@ export default class Client {
|
||||||
private headers: object = {};
|
private headers: object = {};
|
||||||
|
|
||||||
constructor(url: string, key: string|null = null) {
|
constructor(url: string, key: string|null = null) {
|
||||||
this.url = url;
|
// Append tailing slash if omitted from URL string
|
||||||
|
this.url = url.substring(url.length - 1) === "/" ? url : url + "/";
|
||||||
|
|
||||||
// Use API key with requests if defined
|
// Use API key with requests if defined
|
||||||
if (key) {
|
if (key) {
|
||||||
|
@ -24,6 +25,9 @@ export default class Client {
|
||||||
|
|
||||||
// Get fully qualified URL to endpoint
|
// Get fully qualified URL to endpoint
|
||||||
private getEndpoint(endpoint: string): string {
|
private getEndpoint(endpoint: string): string {
|
||||||
|
// Remove leading slash if provided for pathname. It's already set on the domain name
|
||||||
|
endpoint = endpoint.substring(0, 1) !== "/" ? endpoint : endpoint.substring(1, endpoint.length);
|
||||||
|
|
||||||
return this.url + endpoint;
|
return this.url + endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue