diff --git a/.env.local b/.env.local index 6d59b112..ab1e390d 100644 --- a/.env.local +++ b/.env.local @@ -1,9 +1,9 @@ // dev -RELAY_ROOT = https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/ -RELAYURI = "dev-pedw-ns.servicebus.windows.net" -RELAYPATH = "dev-pedw-hc" -SASKEY = "Ml0Y/S/nfRcmIrHFRkO4jNm2J3iH52TSxPiak7+E1+Y=" -SASKEYNAME = "devpedwnspolicy" +//RELAY_ROOT = https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/ +//RELAYURI = "dev-pedw-ns.servicebus.windows.net" +//RELAYPATH = "dev-pedw-hc" +//SASKEY = "Ml0Y/S/nfRcmIrHFRkO4jNm2J3iH52TSxPiak7+E1+Y=" +//SASKEYNAME = "devpedwnspolicy" PORT= "3000" @@ -23,11 +23,11 @@ I18N_DOMAIN = "cymru.local" //preprod -//RELAY_ROOT = https://pp-pedw-ns.servicebus.windows.net/pp-pedw-hc/ -//RELAYURI = "pp-pedw-ns.servicebus.windows.net" -//RELAYPATH = "pp-pedw-hc" -//SASKEY = "JzrOYfMTsGBD1cZHH2nkzqsbfDCqg0brO6jyiIDNVPo=" -//SASKEYNAME = "pppedwnspolicy" +RELAY_ROOT = https://pp-pedw-ns.servicebus.windows.net/pp-pedw-hc/ +RELAYURI = "pp-pedw-ns.servicebus.windows.net" +RELAYPATH = "pp-pedw-hc" +SASKEY = "JzrOYfMTsGBD1cZHH2nkzqsbfDCqg0brO6jyiIDNVPo=" +SASKEYNAME = "pppedwnspolicy" GOOGLE_TAG_MANAGER = GTM-T78CBC3 @@ -39,3 +39,4 @@ NEXT_PUBLIC_ISHARESECRETPHRASE = "Secret phrase" HASHKEY = 028ffbae928d7191c0017f298260995f901d78eabde1436c0af0423459cc3715832136d84f68818d3a96399467b52143e273d4f3bf4ae190848891535421cd6c +NEXT_PUBLIC_HASHKEY = 028ffbae928d7191c0017f298260995f901d78eabde1436c0af0423459cc3715832136d84f68818d3a96399467b52143e273d4f3bf4ae190848891535421cd6c diff --git a/actions/index.js b/actions/index.js index 71d9a7fe..c0455689 100644 --- a/actions/index.js +++ b/actions/index.js @@ -1,6 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; +import HmacSHA256 from "crypto-js/hmac-sha256"; //import {XMLHttpRequest} from 'xmlhttprequest'; @@ -14,6 +15,8 @@ if (process.browser) { } else { BASE_URL = process.env.API_ROOT || `http://localhost:${port}`; } +const WORDKEY = + "028ffbae928d7191c0017f298260995f901d78eabde1436c0af0423459cc3715832136d84f68818d3a96399467b52143e273d4f3bf4ae190848891535421cd6c"; const API_PATH = "/api/data/v8.2/"; @@ -131,6 +134,21 @@ const azureHeadersPaged = (SASToken) => { }; }; +const hashProxyPath = (queryPath) => { + //console.log(CryptoJS.enc.Hex.parse(wordKey)); + //console.log("hasshing this: ", queryPath); + var hashlink = CryptoJS.HmacSHA256( + queryPath, + CryptoJS.enc.Hex.parse(WORDKEY) + ); + hashlink = hashlink.toString(); + hashlink = encodeURI(hashlink); + + console.log(hashlink); + + return "&hash=" + hashlink; +}; + export const getBasicSearch = (token, searchString) => { //console.log("\n\n", token, searchString); @@ -160,22 +178,22 @@ export const getBasicSearch = (token, searchString) => { export const getBasicSearchPaged = (searchString, pageNumber) => { //console.log("\n\n", token, searchString); - var token = getSASToken(); console.log(typeof pageNumber != "undefined"); + + var queryUrl = + "/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" + + searchString + + "') or contains(ticketnumber, '" + + searchString + + "')) and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" + + (typeof pageNumber != "undefined" + ? "&$skiptoken=" + + encodeURI('') + : ""); + return axios - .get( - "/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" + - searchString + - "') or contains(ticketnumber, '" + - searchString + - "')) and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" + - (typeof pageNumber != "undefined" - ? "&$skiptoken=" + - encodeURI('') - : ""), - azureHeadersPaged(token) - ) + .get(queryUrl + hashProxyPath(queryUrl)) .then((res) => { // console.log(" "); // console.log("/////////////////////"); @@ -206,15 +224,15 @@ export const getBasicDNSSearch = (token, searchString) => { export const getBasicDNSSearchPaged = (pageNumber) => { var token = getSASToken(); + var queryUrl = + "/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" + + (typeof pageNumber != "undefined" + ? "&$skiptoken=" + + encodeURI('') + : ""); + return axios - .get( - "/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" + - (typeof pageNumber != "undefined" - ? "&$skiptoken=" + - encodeURI('') - : ""), - azureHeadersPaged(token) - ) + .get(hashProxyPath(queryUrl), azureHeadersPaged(token)) .then((res) => res.data) .catch((error) => { return error.response; @@ -257,7 +275,6 @@ export const getAdvancedSearch = (token, searchString) => { "incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" + queryString + " and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true", - azureHeadersPaged(token) ) .then((res) => res.data) @@ -303,18 +320,17 @@ export const getAdvancedSearchPaged = (searchString, pageNumber) => { searchString.apt : ""; - return axios - .get( - "/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" + - queryString + - " and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" + - (typeof pageNumber != "undefined" - ? "&$skiptoken=" + - encodeURI('') - : ""), + var queryUrl = + "/api/proxy/incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" + + queryString + + " and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true" + + (typeof pageNumber != "undefined" + ? "&$skiptoken=" + + encodeURI('') + : ""); - azureHeadersPaged(token) - ) + return axios + .get(hashProxyPath(queryUrl), azureHeadersPaged(token)) .then((res) => res.data) .catch((error) => { let ErrResponse = { @@ -358,19 +374,18 @@ export const getBasicSearchDetailsPaged = ( incidentID ) => { //console.log("check appealtype:", appealType, caseReference); - var token = getSASToken(); + + var queryUrl = + "/api/proxy/" + + appealTypeName + + "?$filter=_" + + primaryIdAttribute + + "s_value eq " + + incidentID + + "&$count=true"; return axios - .get( - "/api/proxy/" + - appealTypeName + - "?$filter=_" + - primaryIdAttribute + - "s_value eq " + - incidentID + - "&$count=true", - azureHeaders(token) - ) + .get(queryUrl + hashProxyPath(queryUrl)) .then((res) => res.data) .catch((error) => { console.log("this error", error); @@ -411,17 +426,18 @@ export const getSearchDocumentDetailsPaged = (incidentID, pageNumber) => { console.log(incidentID); var token = getSASToken(); + var queryUrl = + "/api/proxy/pinswg_documents?$count=true&$filter=_pinswg_documentids_value eq " + + incidentID + + " and pinswg_publishtoweb eq true&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" + + (typeof pageNumber != "undefined" + ? "&$skiptoken=" + + encodeURI('') + : ""); + + hashProxyPath(queryUrl); return axios - .get( - "/api/proxy/pinswg_documents?$count=true&$filter=_pinswg_documentids_value eq " + - incidentID + - " and pinswg_publishtoweb eq true&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" + - (typeof pageNumber != "undefined" - ? "&$skiptoken=" + - encodeURI('') - : ""), - azureHeadersPaged(token) - ) + .get(hashProxyPath(queryUrl), azureHeadersPaged(token)) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -431,16 +447,15 @@ export const getSearchDocumentDetailsPaged = (incidentID, pageNumber) => { export const getSearchDocumentHistoryPaged = (documentID, pageNumber) => { var token = getSASToken(); + var queryUrl = + "/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " + + documentID + + (typeof pageNumber != "undefined" + ? "&$skiptoken=" + + encodeURI('') + : ""); return axios - .get( - "/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " + - documentID + - (typeof pageNumber != "undefined" - ? "&$skiptoken=" + - encodeURI('') - : ""), - azureHeadersPaged(token) - ) + .get(hashProxyPath(queryUrl), azureHeadersPaged(token)) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -450,12 +465,12 @@ export const getSearchDocumentHistoryPaged = (documentID, pageNumber) => { export const getSearchDocumentDetails1 = (incidentID) => { //console.log(incidentID); var token = getSASToken(); + var queryUrl = + "/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " + + incidentID + + "&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference"; return axios - .get( - "/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " + - incidentID + - "&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" - ) + .get(hashProxyPath(queryUrl)) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -465,16 +480,16 @@ export const getSearchDocumentDetails1 = (incidentID) => { export const getSearchDocumentDetails1Paged = (incidentID, pageNumber) => { //console.log(incidentID); var token = getSASToken(); + var queryUrl = + "/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " + + incidentID + + "&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" + + (typeof pageNumber != "undefined" + ? "&$skiptoken=" + + encodeURI('') + : ""); return axios - .get( - "/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " + - incidentID + - "&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" + - (typeof pageNumber != "undefined" - ? "&$skiptoken=" + - encodeURI('') - : "") - ) + .get(hashProxyPath(queryUrl)) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -484,11 +499,11 @@ export const getSearchDocumentDetails1Paged = (incidentID, pageNumber) => { export const getSearchDocumentHistory1 = (documentID) => { //console.log(documentID); var token = getSASToken(); + var queryUrl = + "/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " + + documentID; return axios - .get( - "/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " + - documentID - ) + .get(hashProxyPath(queryUrl)) .then((res) => { return res.data; }) @@ -500,15 +515,15 @@ export const getSearchDocumentHistory1 = (documentID) => { export const getSearchDocumentHistory1Paged = (documentID, pageNumber) => { //console.log(documentID); var token = getSASToken(); + var queryUrl = + "/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " + + documentID + + (typeof pageNumber != "undefined" + ? "&$skiptoken=" + + encodeURI('') + : ""); return axios - .get( - "/api/proxy/pinswg_documenthistories?$count=true&$select=_pinswg_documentid_value,pinswg_createddate,pinswg_state,pinswg_fileexists,statecode,pinswg_publisheddate&$filter=_pinswg_documentid_value eq " + - documentID + - (typeof pageNumber != "undefined" - ? "&$skiptoken=" + - encodeURI('') - : "") - ) + .get(hashProxyPath(queryUrl)) .then((res) => { return res.data; }) @@ -535,13 +550,13 @@ export const getBasicDNSSearchDetails = (token, appealType, caseReference) => { export const getBasicDNSSearchDetailsPaged = (caseReference) => { var token = getSASToken(); + var queryUrl = + "/api/proxy/pinswg_dnses?$filter=pinswg_name eq '" + + caseReference + + "'&$count=true"; + return axios - .get( - "/api/proxy/pinswg_dnses?$filter=pinswg_name eq '" + - caseReference + - "'&$count=true", - azureHeadersPaged(token) - ) + .get(hashProxyPath(queryUrl), azureHeadersPaged(token)) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -552,12 +567,12 @@ export const getLinkedCases = (parentIncidentid) => { //console.log(parentIncidentid); var token = getSASToken(); + var queryUrl = + "/api/proxy/incidents?$count=true&$filter=_parentcaseid_value eq " + + parentIncidentid + + " and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true &$select=title, incidentid"; return axios - .get( - "/api/proxy/incidents?$count=true&$filter=_parentcaseid_value eq " + - parentIncidentid + - " and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true &$select=title, incidentid," - ) + .get(hashProxyPath(queryUrl)) .then((res) => { //console.log(" linked date", res.data); return res.data; @@ -709,14 +724,15 @@ export const getAppealID = ( }; export const getLogin = (emailAddress, pwd) => { + var queryUrl = + "/api/proxy/contacts?$filter=emailaddress1 eq '" + + emailAddress + + "' and pinswg_custom_password eq '" + + pwd + + "'&$count=true&$select=emailaddress1,%20contactid,pinswg_custom_password, yomifullname, firstname, lastname"; + return axios - .get( - "/api/proxy/contacts?$filter=emailaddress1 eq '" + - emailAddress + - "' and pinswg_custom_password eq '" + - pwd + - "'&$count=true&$select=emailaddress1,%20contactid,pinswg_custom_password, yomifullname, firstname, lastname" - ) + .get(hashProxyPath(queryUrl)) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -834,13 +850,12 @@ export const getMyRepresentations = (token, loggedInUserId) => { }; export const getMyRepresentationsProxy = (token, loggedInUserId) => { + var queryUrl = + "/api/proxy/pinswg_representationses?$filter= _pinswg_contact_value eq " + + loggedInUserId + + "&$count=true&$orderby=createdon desc"; return axios - .get( - "/api/proxy/pinswg_representationses?$filter= _pinswg_contact_value eq " + - loggedInUserId + - "&$count=true&$orderby=createdon desc", - azureHeaders(token) - ) + .get(hashProxyPath(queryUrl)) .then((res) => res.data) .catch((error) => { console.log("this serror", error); @@ -872,13 +887,12 @@ export const deleteMyRepresentations = (myRepresentationsID) => { }; export const getRepresentations = (incidentID) => { + var queryUrl = + "/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " + + incidentID + + " and pinswg_publishtoweb eq true&$count=true&$orderby=createdon desc"; return axios - .get( - "/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " + - incidentID + - " and pinswg_publishtoweb eq true&$count=true&$orderby=createdon desc", - azureHeaders(getSASToken()) - ) + .get(hashProxyPath(queryUrl), azureHeaders(getSASToken())) .then((res) => res.data) .catch((error) => { console.log("this serror", error); @@ -886,13 +900,12 @@ export const getRepresentations = (incidentID) => { }; export const getRepresentationsProxy = (token, incidentID) => { + var queryUrl = + "/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " + + incidentID + + "&$count=true&$orderby=createdon desc"; return axios - .get( - "/api/proxy/pinswg_representationses?$filter= _pinswg_case_value eq " + - incidentID + - "&$count=true&$orderby=createdon desc", - azureHeaders(token) - ) + .get(hashProxyPath(queryUrl), azureHeaders(token)) .then((res) => res.data) .catch((error) => { console.log("this serror", error); @@ -915,13 +928,12 @@ export const getWatchedCases = (token, loggedInUserId) => { }; export const getWatchedCasesProxy = (token, loggedInUserId) => { + var queryUrl = + "/api/proxy/pinswg_watchlists?$filter= _pinswg_contact_value eq " + + loggedInUserId + + "&$count=true&$orderby=createdon desc"; return axios - .get( - "/api/proxy/pinswg_watchlists?$filter= _pinswg_contact_value eq " + - loggedInUserId + - "&$count=true&$orderby=createdon desc", - azureHeaders(token) - ) + .get(hashProxyPath(queryUrl), azureHeaders(token)) .then((res) => res.data) .catch((error) => { console.log("this serror", error); @@ -1011,15 +1023,14 @@ export const getPortalModuleDetailsProxy = ( appealType, caseReference ) => { + var queryUrl = + "/api/proxy/" + + appealType + + "?$filter=pinswg_name eq '" + + caseReference + + "'&$count=true"; return axios - .get( - "/api/proxy/" + - appealType + - "?$filter=pinswg_name eq '" + - caseReference + - "'&$count=true", - azureHeaders(token) - ) + .get(hashProxyPath(queryUrl), azureHeaders(token)) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); @@ -1028,12 +1039,12 @@ export const getPortalModuleDetailsProxy = ( export const getEmailAccountCheck = (emailAddress) => { let token = getSASToken(); + var queryUrl = + "/api/proxy/contacts?$filter=emailaddress1 eq '" + + emailAddress + + "'&$count=true&$select=emailaddress1, contactid"; return axios - .get( - "/api/proxy/contacts?$filter=emailaddress1 eq '" + - emailAddress + - "'&$count=true&$select=emailaddress1, contactid" - ) + .get(hashProxyPath(queryUrl)) .then((res) => res.data) .catch((error) => { console.log("thiserror", error); diff --git a/pages/api/proxy/[...route].js b/pages/api/proxy/[...route].js index cb18967c..c3a6cee0 100644 --- a/pages/api/proxy/[...route].js +++ b/pages/api/proxy/[...route].js @@ -2,6 +2,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; import HmacSHA256 from "crypto-js/hmac-sha256"; +import { rest } from "lodash"; const PROXY_RELAY_URL = "https://" + @@ -48,19 +49,25 @@ const getSASToken = () => { return token; }; -function hashProxyPath(queryPath) { - const wordKey = process.env.HASHKEY; +function checkProxyPath(queryPath) { + var urlHasHash = queryPath.indexOf("&hash="); + + //console.log(queryPath); //, urlHasHash, queryPath.split("&hash=")); + + const WORDKEY = + "028ffbae928d7191c0017f298260995f901d78eabde1436c0af0423459cc3715832136d84f68818d3a96399467b52143e273d4f3bf4ae190848891535421cd6c"; + + const wordKey = WORDKEY; //console.log(CryptoJS.enc.Hex.parse(wordKey)); var hashlink = CryptoJS.HmacSHA256( queryPath, CryptoJS.enc.Hex.parse(wordKey) ); - hashlink = hashlink.toString(CryptoJS.enc.Base64); + hashlink = hashlink.toString(); + hashlink = encodeURI(hashlink); - console.log("&hash=" + hashlink); - - return queryPath; //+ "&hash=" + hashlink; + return hashlink; } export default async function ApiProxy(req, res) { @@ -74,7 +81,9 @@ export default async function ApiProxy(req, res) { var configNoData = { method: req.method, //url: PROXY_RELAY_URL + updateFormCollection + "(" + incidentId + ")", - url: PROXY_RELAY_URL + hashProxyPath(req.url.split("/api/proxy/")[1]), + url: + PROXY_RELAY_URL + + req.url.split("&hash=")[0].split("/api/proxy/")[1], headers: { "OData-MaxVersion": "4.0", "OData-Version": "4.0", @@ -88,7 +97,7 @@ export default async function ApiProxy(req, res) { var config = { method: req.method, - url: PROXY_RELAY_URL + hashProxyPath(req.query.route[0]), + url: PROXY_RELAY_URL + req.query.route[0], headers: { "OData-MaxVersion": "4.0", "OData-Version": "4.0", @@ -102,7 +111,9 @@ export default async function ApiProxy(req, res) { var configDocument = { method: req.method, - url: PROXY_RELAY_URL + hashProxyPath(req.url.split("/api/proxy/")[1]), + url: + PROXY_RELAY_URL + + req.url.split("&hash=")[0].split("/api/proxy/")[1], headers: { "OData-MaxVersion": "4.0", "OData-Version": "4.0", @@ -115,15 +126,34 @@ export default async function ApiProxy(req, res) { }; return new Promise((resolve, reject) => { - let apiPath = req.url.split("/api/proxy/")[1]; + let hashCheckPath = req.url.split("&hash=")[0]; + let hashCheckValue = req.url.split("&hash=")[1]; + let hashFromRequest = checkProxyPath(hashCheckPath); + let apiPath = ""; + + // console.log(req.url); + console.log("Check:", hashCheckValue); + + // if (hashCheckPath > 0) { + // hashCheckValue = req.url.split("&hash=")[1]; + // apiPath = req.url.split("&hash=")[0].split("/api/proxy")[1]; + // } else { + // apiPath = req.url.split("/api/proxy")[1]; + // } + //console.log(hashCheckPath); + console.log("Calculated:", hashFromRequest); + + //console.log(req.url.split("&hash=")[0].split("/api/proxy/")[1]); + //console.log(hashCheckPath); + // console.log("from proxy :", hashCheckValue); + // // console.log(req.url); + // // console.log(apiPath); + // console.log("hashing path", hashFromRequest); + let hasDocument = apiPath.indexOf("/download") > 0 ? true : false; - // console.log( - // "//////////////", - // req.url.split("/api/proxy/")[1], - // PROXY_RELAY_URL + req.query.route[0], - // req.method, - // hasDocument - // ); + + // hashCheckValue == hashFromRequest + //? axios( req.method == "GET" ? hasDocument @@ -151,9 +181,11 @@ export default async function ApiProxy(req, res) { }) .catch((error) => { console.log("proxy response error", error); - res.json(error); + // res.json(error); res.status(405).end(); return resolve(); }); + // : res.status(405).end(); + // return resolve(); }); }