Skip to content

Commit f716743

Browse files
committed
Adress PR comments
1 parent 61bbeb9 commit f716743

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

src/lib/meilisearch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MeiliSearch {
2727
httpRequest: HttpRequests
2828

2929
constructor(config: Config) {
30-
config = addProtocolIfNotPresent(config)
30+
config.host = addProtocolIfNotPresent(config.host)
3131
config.host = HttpRequests.addTrailingSlash(config.host)
3232
this.config = config
3333
this.httpRequest = new HttpRequests(config)

src/lib/utils.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Config } from '../types'
2-
31
/**
42
* Removes undefined entries from object
53
*/
@@ -15,16 +13,11 @@ async function sleep(ms: number): Promise<void> {
1513
return await new Promise((resolve) => setTimeout(resolve, ms))
1614
}
1715

18-
function addProtocolIfNotPresent(config: Config): Config {
19-
if (
20-
!(config.host.startsWith('https://') || config.host.startsWith('http://'))
21-
) {
22-
return {
23-
...config,
24-
host: 'http://' + config.host,
25-
}
16+
function addProtocolIfNotPresent(host: string): string {
17+
if (!(host.startsWith('https://') || host.startsWith('http://'))) {
18+
return `http://${host}`
2619
}
27-
return config
20+
return host
2821
}
2922

3023
export { sleep, removeUndefinedFromObject, addProtocolIfNotPresent }

0 commit comments

Comments
 (0)