Skip to content

Commit

Permalink
refactor: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsaplin committed Dec 8, 2023
1 parent 28a68ba commit 8ad9bd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
5 changes: 1 addition & 4 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ function loadDelayed() {
}

async function loadPage() {
loadTargetOffers(
'sitesinternal',
'https://dev--helix-target-integration--vtsaplin.hlx.live',
);
loadTargetOffers('sitesinternal');
await loadEager(document);
await loadLazy(document);
loadDelayed();
Expand Down
15 changes: 7 additions & 8 deletions scripts/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,16 @@ function getApplicableOffers(data) {
/**
* Fetch offers for a client and a host.
* @param client
* @param host
* @param url
* @param sessionId
* @returns {Promise<any>}
*/
async function fetchOffers(client, host, sessionId) {
const url = `https://${client}.tt.omtrdc.net/rest/v1/delivery?client=${client}&sessionId=${sessionId}`;

async function fetchOffers(client, url, sessionId) {
const payload = {
context: {
channel: 'web',
address: {
url: host,
url,
},
},
execute: {
Expand All @@ -103,7 +101,7 @@ async function fetchOffers(client, host, sessionId) {
body: JSON.stringify(payload),
};

const response = await fetch(url, options);
const response = await fetch(`/rest/v1/delivery?client=${client}&sessionId=${sessionId}`, options);
if (!response.ok) {
throw new Error(`Failed to fetch offers: ${response.status} ${response.statusText}`);
}
Expand Down Expand Up @@ -209,9 +207,10 @@ function getSectionByElementSelector(selector) {
/**
* Start targeting for a client on a host.
* @param client The client.
* @param host The host.
*/
export default function loadTargetOffers(client, host) {
export default function loadTargetOffers(client) {
const host = `${window.location.protocol}//${window.location.host}`;

// eslint-disable-next-line no-console
console.debug(`Loading offers for client ${client} on host ${host}`);

Expand Down

0 comments on commit 8ad9bd3

Please sign in to comment.