Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Sep 24, 2021
1 parent 0c2a5d7 commit 57f984e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
13 changes: 7 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const applyConfig = (config) => {

const handler = createHandler({
urlES: process.env.RAZZLE_PROXY_ES_DSN || 'http://localhost:9200/_all',
urlQA:
process.env.RAZZLE_PROXY_QA_DSN || 'http://localhost:8000/api/query',
urlNLP: process.env.RAZZLE_PROXY_QA_DSN || 'http://localhost:8000/api',
});

const middleware = express.Router();
Expand All @@ -55,10 +54,12 @@ export const installGlobalSearch = (config) => {
// config.settings.devProxyToApiPath = false;
config.settings.searchlib = installConfig(config.settings.searchlib);
config.settings.searchlib.resolve.LeftColumnLayout.component = LeftColumnLayout;
config.settings.searchlib.searchui.globalsearch.elastic_index =
'_es/globalsearch';
config.settings.searchlib.searchui.globalsearch.layoutComponent =
'LeftColumnLayout';

const { globalsearch } = config.settings.searchlib.searchui;

globalsearch.elastic_index = '_es/globalsearch';
globalsearch.layoutComponent = 'LeftColumnLayout';

return config;
};

Expand Down
26 changes: 16 additions & 10 deletions src/middleware/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function filterRequests(req, whitelist, retVal) {
}

function handleQuestionRequest(req, res, params) {
const { urlQA } = params;
const { urlNLP } = params;
const { body } = req;
const { question } = body;

Expand All @@ -35,7 +35,7 @@ function handleQuestionRequest(req, res, params) {
};

superagent
.post(urlQA)
.post(urlNLP)
.send(qaBody)
.set('accept', 'application/json')
.end((err, resp) => {
Expand All @@ -48,6 +48,7 @@ function handleSearchRequest(req, res, params) {
const { urlES } = params;
const url = `${urlES}/_search`;

console.log('handle search', url);
superagent
.post(url)
.send(body)
Expand All @@ -59,10 +60,10 @@ function handleSearchRequest(req, res, params) {

function handleNlpRequest(req, res, params) {
const { body } = req;
const { urlQA } = params;
const { urlNLP } = params;
const { endpoint } = body;
delete body.endpoint;
const url = `${urlQA}/${endpoint}`;
const url = `${urlNLP}/${endpoint}`;

superagent
.post(url)
Expand Down Expand Up @@ -93,19 +94,19 @@ const handleSearch = (req, res, next, params) => {
}
};

const handleSettings = (req, res, next, { appName, urlQA, urlES }) => {
const handleSettings = (req, res, next, { appName, urlNLP, urlES }) => {
const url = `${urlES}/_settings`;
superagent.get(url).end((err, resp) => {
if (resp && resp.body) res.send(resp.body);
});
};

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

export const createHandler = ({ urlQA, urlES }) => {
export const createHandler = ({ urlNLP, urlES }) => {
return function esProxyHandler(req, res, next) {
const appNames = Object.keys(config.settings.searchlib.searchui);

Expand All @@ -115,7 +116,12 @@ export const createHandler = ({ urlQA, urlES }) => {
.find((b) => b);

if (appName) {
handleSearch(req, res, next, { appName, urlQA, urlES });
const conf = config.settings.searchlib.searchui[appName];
handleSearch(req, res, next, {
appName,
urlNLP,
urlES: conf.enableNLP ? urlNLP : urlES,
});
return;
}

Expand All @@ -124,7 +130,7 @@ export const createHandler = ({ urlQA, urlES }) => {
.find((b) => b);

if (appName) {
handleSettings(req, res, next, { appName, urlQA, urlES });
handleSettings(req, res, next, { appName, urlNLP, urlES });
return;
}

Expand All @@ -133,7 +139,7 @@ export const createHandler = ({ urlQA, urlES }) => {
.find((b) => b);

if (appName) {
handleDownload(req, res, next, { appName, urlQA, urlES });
handleDownload(req, res, next, { appName, urlNLP, urlES });
return;
}

Expand Down

0 comments on commit 57f984e

Please sign in to comment.