Skip to content

Commit

Permalink
Merge pull request #1007 from City-of-Helsinki/UHF-10102-support-elas…
Browse files Browse the repository at this point in the history
…tic-nginx-proxy

UHF-10102: Fixes for nginx elasticsearch proxy.
  • Loading branch information
juho-lehmonen authored Jun 13, 2024
2 parents f0a50c9 + 7f65708 commit ef5b399
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/js/job-search.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/js/react/apps/job-search/enum/Global.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Global = {
index: 'job_listings',
size: 30,
sortOptions: {
closing: 'closing',
Expand Down
4 changes: 3 additions & 1 deletion src/js/react/apps/job-search/hooks/useIndexQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useSWR from 'swr';
import { PublicConfiguration } from 'swr/_internal';
import Global from '../enum/Global';

type UseIndexQueryProps = {
// Uses _mquery endpoint if true
Expand All @@ -14,10 +15,11 @@ const useIndexQuery = ({ query, multi, ...rest }: UseIndexQueryProps) => {
const fetcher = () => {
const proxyUrl = drupalSettings?.helfi_react_search?.elastic_proxy_url;
const url: string|undefined = proxyUrl;
const { index } = Global;
const endpoint = multi ? '_msearch' : '_search';
const contentType = `application/${multi ? 'x-ndjson' : 'json'}`;

return fetch(`${url}/${endpoint}`, {
return fetch(`${url}/${index}/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': contentType,
Expand Down
6 changes: 4 additions & 2 deletions src/js/react/apps/job-search/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getLanguageLabel } from './helpers/Language';
import sortOptions from './helpers/Options';
import { AGGREGATIONS, EMPLOYMENT_FILTER_OPTIONS, LANGUAGE_OPTIONS, PROMOTED_IDS, TASK_AREA_OPTIONS } from './query/queries';
import type OptionType from './types/OptionType';
import Global from './enum/Global';
import type Term from './types/Term';
import type URLParams from './types/URLParams';
import AggregationItem from './types/AggregationItem';
Expand Down Expand Up @@ -105,6 +106,7 @@ type configurations = {

export const configurationsAtom = atom(async(): Promise<configurations> => {
const proxyUrl = drupalSettings?.helfi_react_search?.elastic_proxy_url;
const { index } = Global;
const url: string | undefined = proxyUrl;
const ndjsonHeader = '{}';

Expand All @@ -130,7 +132,7 @@ export const configurationsAtom = atom(async(): Promise<configurations> => {
JSON.stringify(PROMOTED_IDS)
}\n`;

return fetch(`${url}/_msearch`, {
return fetch(`${url}/${index}/_msearch`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-ndjson',
Expand Down Expand Up @@ -307,7 +309,7 @@ export const areaFilterAtom = atom(
{
label: item.label,
value: item.key,
}
}
)
));

Expand Down

0 comments on commit ef5b399

Please sign in to comment.