Skip to content

Commit

Permalink
In the middleware, read request params from frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Oct 7, 2021
1 parent 1df43fd commit e52e354
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/SearchBlock/SearchBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default function SearchBlockView(props) {
data,
schema,
);
console.log('registry', { data, registry });
return (
<div className="searchlib-block">
<SearchApp registry={registry} appName={appName} mode={mode} />
Expand Down
18 changes: 9 additions & 9 deletions src/SearchBlock/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export const SearchBlockSchema = ({ formData = {} }) => ({
title: 'General settings',
fields: ['headline', 'subheadline', 'enableNLP'],
},
// ...(formData.enableNLP
// ? [
// {
// id: 'nlp',
// title: 'NLP Capabilities Settings',
// fields: ['use_qa_dp', 'qa_queryTypes', 'cutoffScore'],
// },
// ]
// : []),
...(formData?.enableNLP
? [
{
id: 'nlp',
title: 'NLP Capabilities Settings',
fields: ['use_qa_dp', 'qa_queryTypes', 'cutoffScore'],
},
]
: []),
],

properties: {
Expand Down
24 changes: 19 additions & 5 deletions src/middleware/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ function handleSearchRequest(req, res, params) {
const { body } = req;
const { urlES } = params;
const url = `${urlES}/_search`;
console.log('handle search', url, urlES);
if (body?.params?.config) {
delete body.params.config;
}
// console.log('handle search', url, urlES);

superagent
.post(url)
Expand All @@ -41,8 +44,13 @@ function handleNlpRequest(req, res, params) {
const { urlNLP } = params;
const { endpoint } = body;
delete body.endpoint;

if (body?.params?.config) {
delete body.params.config;
}

const url = `${urlNLP}/${endpoint}`;
console.log('handle nlp', url, urlNLP);
// console.log('handle nlp', url, urlNLP);

superagent
.post(url)
Expand Down Expand Up @@ -78,7 +86,9 @@ const handleSettings = (req, res, next, { appName, urlNLP, urlES }) => {
};

const handleDownload = (req, res, next, { appName, urlNLP, urlES }) => {
const appConfig = config.settings.searchlib.searchui[appName];
const body = req.body || {};
const appConfig =
body.params?.config || config.settings.searchlib.searchui[appName];
download(urlES, appConfig, req, res);
};

Expand All @@ -92,8 +102,12 @@ export const createHandler = ({ urlNLP, urlES }) => {
.find((b) => b);

if (appName) {
const conf = config.settings.searchlib.searchui[appName];
console.log('conf', appName, conf.enableNLP);
const body = req.body || {};
const conf =
body.params?.config || config.settings.searchlib.searchui[appName];

// console.log('conf', appName, conf.enableNLP);

handleSearch(req, res, next, {
appName,
urlNLP,
Expand Down

0 comments on commit e52e354

Please sign in to comment.