Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
scale-tone committed Jan 9, 2025
1 parent 4a1d59c commit 8ca2b1f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
24 changes: 16 additions & 8 deletions api/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ const httpTrigger: AzureFunction = async function (context: Context, req: HttpRe
const searchApiUrl = `https://${process.env.SearchServiceName}.search.windows.net/indexes/${process.env.SearchIndexName}/docs/autocomplete?api-version=2019-05-06&`;
const url = req.url.replace(/^http(s)?:\/\/[^/]+\/api\/autocomplete(\?)?/i, searchApiUrl);

const searchApiResponse = await axios.get(url, {
headers: {
"api-key": process.env.SearchApiKey,
} });
try {

const response = await axios.get(url, {
headers: {
"api-key": process.env.SearchApiKey,
} });

context.res = {
status: response.status,
body: response.data,
};

context.res = {
status: searchApiResponse.status,
body: searchApiResponse.data,
};
} catch (err) {
context.res = {
status: err.response?.status ?? 500
};
}
};

export default httpTrigger;
26 changes: 17 additions & 9 deletions api/lookup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ const httpTrigger: AzureFunction = async function (context: Context, req: HttpRe
const searchApiUrl = `https://${process.env.SearchServiceName}.search.windows.net/indexes/${process.env.SearchIndexName}/docs`;
const url = req.url.replace(/^http(s)?:\/\/[^/]+\/api\/lookup/i, searchApiUrl);

const searchApiResponse = await axios.get(`${url}?api-version=2019-05-06`, {
headers: {
"api-key": process.env.SearchApiKey,
} });

context.res = {
status: searchApiResponse.status,
body: searchApiResponse.data,
};
try {

const response = await axios.get(`${url}?api-version=2019-05-06`, {
headers: {
"api-key": process.env.SearchApiKey,
} });

context.res = {
status: response.status,
body: response.data,
};

} catch (err) {
context.res = {
status: err.response?.status ?? 500
};
}
};

export default httpTrigger;
26 changes: 17 additions & 9 deletions api/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ const httpTrigger: AzureFunction = async function (context: Context, req: HttpRe
const searchApiUrl = `https://${process.env.SearchServiceName}.search.windows.net/indexes/${process.env.SearchIndexName}/docs?api-version=2019-05-06&`;
const url = req.url.replace(/^http(s)?:\/\/[^/]+\/api\/search(\?)?/i, searchApiUrl);

const searchApiResponse = await axios.get(url, {
headers: {
"api-key": process.env.SearchApiKey,
} });

context.res = {
status: searchApiResponse.status,
body: searchApiResponse.data,
};
try {

const response = await axios.get(url, {
headers: {
"api-key": process.env.SearchApiKey,
} });

context.res = {
status: response.status,
body: response.data,
};

} catch (err) {
context.res = {
status: err.response?.status ?? 500
};
}
};

export default httpTrigger;

0 comments on commit 8ca2b1f

Please sign in to comment.