diff --git a/src/api.ts b/src/api.ts index be4b919a1d..453e1ca38a 100644 --- a/src/api.ts +++ b/src/api.ts @@ -51,13 +51,6 @@ import { import AudioData from 'types/AudioData'; import { MushafLines, QuranFont } from 'types/QuranReader'; -export const SEARCH_FETCH_OPTIONS = { - headers: { - // eslint-disable-next-line @typescript-eslint/naming-convention - 'x-api-key': process.env.NEXT_PUBLIC_SEARCH_API_KEY, - }, -}; - export const OFFLINE_ERROR = 'OFFLINE'; export const X_AUTH_SIGNATURE = 'x-auth-signature'; @@ -250,7 +243,7 @@ export const getAdvancedCopyRawResult = async ( */ export const getNewSearchResults = async ( params: SearchRequestParams, -): Promise => fetcher(makeNewSearchResultsUrl(params), SEARCH_FETCH_OPTIONS); +): Promise => fetcher(makeNewSearchResultsUrl(params)); /** * Get the list of tafsirs. diff --git a/src/utils/apiPaths.ts b/src/utils/apiPaths.ts index b1703e1ecb..9441a2e312 100644 --- a/src/utils/apiPaths.ts +++ b/src/utils/apiPaths.ts @@ -3,6 +3,7 @@ import { decamelizeKeys } from 'humps'; // eslint-disable-next-line import/no-cycle import { getDefaultWordFields, getMushafId, ITEMS_PER_PAGE, makeUrl } from './api'; import stringify from './qs-stringify'; +import { getProxiedServiceUrl } from './url'; import { DEFAULT_RECITER } from '@/redux/defaultSettings/defaultSettings'; import { @@ -146,15 +147,10 @@ export const makeTranslationsInfoUrl = (locale: string, translations: number[]): export const makeAdvancedCopyUrl = (params: AdvancedCopyRequest): string => makeUrl('/verses/advanced_copy', params as Record); -export const makeNewSearchApiUrl = (params: Record) => { - const baseUrl = process.env.NEXT_PUBLIC_SEARCH_BASE_URL; - - return `${baseUrl}/v1/search?${stringify(decamelizeKeys(params))}`; +export const makeNewSearchResultsUrl = (params: SearchRequestParams) => { + return getProxiedServiceUrl('search/v1/search', `?${stringify(decamelizeKeys(params))}`); }; -export const makeNewSearchResultsUrl = (params: SearchRequestParams) => - makeNewSearchApiUrl(params); - /** * Compose the url for the navigation search API that is used to show results inside the command bar. * diff --git a/src/utils/auth/apiPaths.ts b/src/utils/auth/apiPaths.ts index 91bb98d196..a3b019b051 100644 --- a/src/utils/auth/apiPaths.ts +++ b/src/utils/auth/apiPaths.ts @@ -9,14 +9,14 @@ import { EstimateGoalRequest, GoalCategory } from '@/types/auth/Goal'; import { StreakWithMetadataParams } from '@/types/auth/Streak'; import { MediaType } from '@/types/Media/GenerateMediaFileRequest'; import { Mushaf } from '@/types/QuranReader'; -import { getAuthApiPath } from '@/utils/url'; +import { getProxiedServiceUrl } from '@/utils/url'; import BookmarkType from 'types/BookmarkType'; export const makeUrl = (url: string, parameters?: Record): string => { if (!parameters) { - return getAuthApiPath(url); + return getProxiedServiceUrl('auth/', url); } - return getAuthApiPath(`${url}${`?${stringify(parameters)}`}`); + return getProxiedServiceUrl('auth/', `${url}${`?${stringify(parameters)}`}`); }; export const makeUserProfileUrl = (): string => makeUrl('users/profile'); diff --git a/src/utils/url.ts b/src/utils/url.ts index ac266250fd..5b6d18c1e9 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -49,16 +49,10 @@ export const getBasePath = (): string => process.env.NEXT_PUBLIC_VERCEL_URL }`; -/** - * Get the auth api path. - * - * @param {string} path - * @returns {string} - */ -export const getAuthApiPath = (path: string): string => { - const PROXY_PATH = '/api/proxy/auth/'; +export const getProxiedServiceUrl = (service: string, path: string): string => { + const PROXY_PATH = `/api/proxy/${service}`; const BASE_PATH = isStaticBuild - ? `${process.env.API_GATEWAY_URL}/auth/` + ? `${process.env.API_GATEWAY_URL}/${service}` : `${getBasePath()}${PROXY_PATH}`; return `${BASE_PATH}${path}`; };