Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call API Gateway for search #2253

Open
wants to merge 6 commits into
base: QF-993-search-as-you-type-POC
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -250,7 +243,7 @@ export const getAdvancedCopyRawResult = async (
*/
export const getNewSearchResults = async <T extends SearchMode>(
params: SearchRequestParams<T>,
): Promise<NewSearchResponse> => fetcher(makeNewSearchResultsUrl(params), SEARCH_FETCH_OPTIONS);
): Promise<NewSearchResponse> => fetcher(makeNewSearchResultsUrl(params));

/**
* Get the list of tafsirs.
Expand Down
10 changes: 3 additions & 7 deletions src/utils/apiPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -146,15 +147,10 @@ export const makeTranslationsInfoUrl = (locale: string, translations: number[]):
export const makeAdvancedCopyUrl = (params: AdvancedCopyRequest): string =>
makeUrl('/verses/advanced_copy', params as Record<string, unknown>);

export const makeNewSearchApiUrl = (params: Record<string, any>) => {
const baseUrl = process.env.NEXT_PUBLIC_SEARCH_BASE_URL;

return `${baseUrl}/v1/search?${stringify(decamelizeKeys(params))}`;
export const makeNewSearchResultsUrl = <T extends SearchMode>(params: SearchRequestParams<T>) => {
return getProxiedServiceUrl('search/v1/search', `?${stringify(decamelizeKeys(params))}`);
};

export const makeNewSearchResultsUrl = <T extends SearchMode>(params: SearchRequestParams<T>) =>
makeNewSearchApiUrl(params);

/**
* Compose the url for the navigation search API that is used to show results inside the command bar.
*
Expand Down
6 changes: 3 additions & 3 deletions src/utils/auth/apiPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, unknown>): 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');
Expand Down
12 changes: 3 additions & 9 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
};