Skip to content

Commit

Permalink
Revert "refactor: ensure urls have the correct suffix when building t…
Browse files Browse the repository at this point in the history
…he clients"

This reverts commit d6fd4d1.
  • Loading branch information
aleortega committed Feb 4, 2025
1 parent d6fd4d1 commit 9315a5b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
10 changes: 3 additions & 7 deletions src/client/ContentClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,9 @@ export async function downloadContent(
)
}

function sanitizeUrlWithContentPath(url: string): string {
return sanitizeUrl(url, '/content')
}

export function createContentClient(options: ClientOptions): ContentClient {
const { fetcher, logger } = options
const contentUrl = sanitizeUrlWithContentPath(options.url)
const contentUrl = sanitizeUrl(options.url)
const defaultParallelConfig = options?.parallelConfig

async function fetchFromMultipleServersRace(
Expand All @@ -102,7 +98,7 @@ export function createContentClient(options: ClientOptions): ContentClient {

urls.forEach(async (url) => {
try {
const serverUrl = sanitizeUrlWithContentPath(url)
const serverUrl = sanitizeUrl(url)
const response = await fetcher.fetch(`${serverUrl}${path}`, requestOptionsWithSignal)

if (signal.aborted) {
Expand Down Expand Up @@ -148,7 +144,7 @@ export function createContentClient(options: ClientOptions): ContentClient {
const results = await Promise.allSettled(
urls.map(async (url) => {
try {
const serverUrl = sanitizeUrlWithContentPath(url)
const serverUrl = sanitizeUrl(url)
const response = await fetcher.fetch(`${serverUrl}${path}`, requestOptions)
return await response.json()
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions src/client/LambdasClient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as client from './specs/lambdas-client'
import { sanitizeUrl } from './utils/Helper'
import { ClientOptions } from './types'
import { CustomClient } from './utils/fetcher'
import { sanitizeUrl } from './utils/Helper'
import * as client from './specs/lambdas-client'

export type LambdasClient = ReturnType<typeof createLambdasClient>

export function createLambdasClient(options: ClientOptions) {
const lambdasUrl = sanitizeUrl(options.url, '/lambdas')
const lambdasUrl = sanitizeUrl(options.url)

function wrap<T extends (...args: any) => CustomClient<any>>(f: T) {
return (...args: Parameters<T>): ReturnType<ReturnType<T>> => {
Expand Down
6 changes: 1 addition & 5 deletions src/client/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function isValidQueryParamValue(value: any): boolean {
}

/** Remove white spaces and add https if no protocol is specified */
export function sanitizeUrl(url: string, ensurePathPrefix?: string): string {
export function sanitizeUrl(url: string): string {
// Remove empty spaces
url = url.trim()

Expand All @@ -235,10 +235,6 @@ export function sanitizeUrl(url: string, ensurePathPrefix?: string): string {
url = url.slice(0, -1)
}

if (ensurePathPrefix && !url.endsWith(ensurePathPrefix)) {
url += ensurePathPrefix
}

return url
}

Expand Down

0 comments on commit 9315a5b

Please sign in to comment.