Skip to content

Commit 078c1cb

Browse files
author
Laurynas Butkus
committed
Normalize base uri
1 parent c4e8cee commit 078c1cb

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default class Client {
101101
}
102102

103103
url(path) {
104-
return `${this.api.baseUri}/${path}?secret=${this.api.secret}`;
104+
return `${this.api.baseUri}${path}?secret=${this.api.secret}`;
105105
}
106106

107107
static handleError(error) {

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import path from 'path';
22
import pkg from '../package.json';
33
import Task from './task';
44
import Client from './client';
5-
import { getReadableStream } from './utils';
5+
import { getReadableStream, normalizeBaseUri } from './utils';
66

77
function ConvertAPI(secret, options = {}) {
88
if (!(this instanceof ConvertAPI)) {
99
return new ConvertAPI(secret, options);
1010
}
1111

1212
this.secret = secret;
13-
this.baseUri = options.baseUri || 'https://v2.convertapi.com';
13+
this.baseUri = normalizeBaseUri(options.baseUri || 'https://v2.convertapi.com/');
1414
this.conversionTimeout = options.conversionTimeout;
1515
this.conversionTimeoutDelta = options.conversionTimeoutDelta || 10;
1616
this.uploadTimeout = options.uploadTimeout || 1800;

src/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ export const normalizeFilesParam = async (promise) => {
2121
return Promise.all(value);
2222
};
2323

24+
export const normalizeBaseUri = (baseUri) => {
25+
if (baseUri[baseUri.length - 1] !== '/') {
26+
return `${baseUri}/`;
27+
}
28+
29+
return baseUri;
30+
};
31+
2432
export const buildFileParam = async (api, value) => {
2533
if (URI_REGEXP.test(value)) {
2634
return value;

0 commit comments

Comments
 (0)