moved hashapipath to reusable single helper

This commit is contained in:
2026-03-16 11:13:41 +00:00
parent 023a8e9e6d
commit 18dfc60754
74 changed files with 298 additions and 1149 deletions
+23 -36
View File
@@ -21,25 +21,12 @@ import _ from "lodash";
import { azureHeaders } from "../../../actions/core/headers";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
const WORDKEY = process.env.HASHKEY;
import { hashAPIPath } from "../../../actions/core/hash";
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
const hashAPIPath = (queryPath) => {
var hashlink = CryptoJS.HmacSHA256(
queryPath,
CryptoJS.enc.Hex.parse(WORDKEY)
);
hashlink = hashlink.toString(CryptoJS.enc.Hex);
//return "&hash=" + hashlink;
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
};
export default async function ApiProxy(req, res) {
var searchString = req.query.searchString;
var token = await getToken();
@@ -54,28 +41,28 @@ export default async function ApiProxy(req, res) {
var apiResponse = _.isEmpty(req.query)
? res.status(400).json()
: searchString.length > 0
? axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token)
)
.then(({ data }) => {
//console.log(
"\n==========================================\n",
// "basic search incident: " + queryUrl,
// "\n\n",
// "data: " + JSON.stringify(data),
// "\n\n",
"publihs:" + JSON.stringify(data.value[0]),
"\n==========================================\n";
//);
return res.status(200).json(data);
})
.catch((error) => {
consoleLogger(error);
res.status(400).json(error);
})
: res.status(400).json();
? axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token)
)
.then(({ data }) => {
//console.log(
("\n==========================================\n",
// "basic search incident: " + queryUrl,
// "\n\n",
// "data: " + JSON.stringify(data),
// "\n\n",
"publihs:" + JSON.stringify(data.value[0]),
"\n==========================================\n");
//);
return res.status(200).json(data);
})
.catch((error) => {
consoleLogger(error);
res.status(400).json(error);
})
: res.status(400).json();
return apiResponse;
}