diff --git a/src/routes/etf/+page.ts b/src/routes/etf/+page.ts
index 8ece1d28..ce1df4af 100644
--- a/src/routes/etf/+page.ts
+++ b/src/routes/etf/+page.ts
@@ -1,24 +1,8 @@
-import { userRegion, getCache, setCache } from '$lib/store';
-
-
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-
-userRegion.subscribe(value => {
-
- if (usRegion.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
+import { getCache, setCache } from '$lib/store';
-export const load = async () => {
+export const load = async ({parent}) => {
const getETFList = async () => {
let output;
@@ -28,7 +12,7 @@ export const load = async () => {
output = cachedData;
} else {
-
+ const {apiKey, apiURL} = await parent();
// make the POST request to the endpoint
const response = await fetch(apiURL + '/all-etf-tickers', {
method: 'GET',
diff --git a/src/routes/etf/[tickerID]/congress-trading/+page.ts b/src/routes/etf/[tickerID]/congress-trading/+page.ts
index 3d61f5a9..fcab32d7 100644
--- a/src/routes/etf/[tickerID]/congress-trading/+page.ts
+++ b/src/routes/etf/[tickerID]/congress-trading/+page.ts
@@ -10,16 +10,16 @@ export const load = async ({ parent, params }) => {
if (cachedData) {
output = cachedData;
} else {
- const data = await parent();
+ const {apiKey, apiURL} = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
- const response = await fetch(data?.apiURL + '/congress-trading-ticker', {
+ const response = await fetch(apiURL + '/congress-trading-ticker', {
method: 'POST',
headers: {
- "Content-Type": "application/json", "X-API-KEY": data?.apiKey
+ "Content-Type": "application/json", "X-API-KEY": apiKey
},
body: JSON.stringify(postData)
});
diff --git a/src/routes/etf/[tickerID]/dividends/+page.ts b/src/routes/etf/[tickerID]/dividends/+page.ts
index f1d4df5e..89ce0614 100644
--- a/src/routes/etf/[tickerID]/dividends/+page.ts
+++ b/src/routes/etf/[tickerID]/dividends/+page.ts
@@ -10,16 +10,16 @@ export const load = async ({ parent, params }) => {
if (cachedData) {
newsList = cachedData;
} else {
- const data = await parent();
+ const {apiKey, apiURL} = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
- const response = await fetch(data?.apiURL + '/stock-dividend', {
+ const response = await fetch(apiURL + '/stock-dividend', {
method: 'POST',
headers: {
- "Content-Type": "application/json", "X-API-KEY": data?.apiKey
+ "Content-Type": "application/json", "X-API-KEY": apiKey
},
body: JSON.stringify(postData)
});
diff --git a/src/routes/etf/[tickerID]/holdings/+page.ts b/src/routes/etf/[tickerID]/holdings/+page.ts
index 1e887561..edf0bd7d 100644
--- a/src/routes/etf/[tickerID]/holdings/+page.ts
+++ b/src/routes/etf/[tickerID]/holdings/+page.ts
@@ -11,16 +11,16 @@ export const load = async ({ parent, params }) => {
if (cachedData) {
output = cachedData;
} else {
- const data = await parent();
+ const {apiKey, apiURL} = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
- const response = await fetch(data?.apiURL + '/etf-holdings', {
+ const response = await fetch(apiURL + '/etf-holdings', {
method: 'POST',
headers: {
- "Content-Type": "application/json", "X-API-KEY": data?.apiKey
+ "Content-Type": "application/json", "X-API-KEY": apiKey
},
body: JSON.stringify(postData)
});
diff --git a/src/routes/etf/[tickerID]/news/+page.ts b/src/routes/etf/[tickerID]/news/+page.ts
index 6c33e180..d828fced 100644
--- a/src/routes/etf/[tickerID]/news/+page.ts
+++ b/src/routes/etf/[tickerID]/news/+page.ts
@@ -10,16 +10,16 @@ export const load = async ({ parent, params }) => {
if (cachedData) {
output = cachedData;
} else {
- const data = await parent();
+ const {apiKey, apiURL} = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
- const response = await fetch(data?.apiURL + '/stock-news', {
+ const response = await fetch(apiURL + '/stock-news', {
method: 'POST',
headers: {
- "Content-Type": "application/json", "X-API-KEY": data?.apiKey
+ "Content-Type": "application/json", "X-API-KEY": apiKey
},
body: JSON.stringify(postData)
});
diff --git a/src/routes/etf/[tickerID]/options/+page.ts b/src/routes/etf/[tickerID]/options/+page.ts
index a0d3f221..800bda47 100644
--- a/src/routes/etf/[tickerID]/options/+page.ts
+++ b/src/routes/etf/[tickerID]/options/+page.ts
@@ -1,19 +1,4 @@
-import { userRegion, getCache, setCache } from '$lib/store';
-
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL = import.meta.env.VITE_EU_API_URL; // Set a default API URL
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-userRegion.subscribe(value => {
-
- if (usRegion.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
-
+import { getCache, setCache } from '$lib/store';
function daysLeft(targetDate) {
@@ -28,9 +13,10 @@ function daysLeft(targetDate) {
}
-export const load = async ({ params }) => {
+export const load = async ({ parent, params }) => {
+
+ const {apiKey, apiURL} = await parent();
-
const getOptionsPlotData = async () => {
let res;
@@ -39,7 +25,6 @@ export const load = async ({ params }) => {
res = cachedData;
} else {
- // make the POST request to the endpoint
const postData = {
ticker: params.tickerID
};
diff --git a/src/routes/etf/[tickerID]/stats/+page.ts b/src/routes/etf/[tickerID]/stats/+page.ts
index df51af88..9a049615 100644
--- a/src/routes/etf/[tickerID]/stats/+page.ts
+++ b/src/routes/etf/[tickerID]/stats/+page.ts
@@ -1,19 +1,7 @@
-import { userRegion, getCache, setCache } from '$lib/store';
-
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-userRegion.subscribe(value => {
-if (usRegion.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
-} else {
- apiURL = import.meta.env.VITE_EU_API_URL;
-}
-});
+import { getCache, setCache } from '$lib/store';
-export const load = async ({ params }) => {
+export const load = async ({ parent, params }) => {
const getQuantStats = async () => {
@@ -24,6 +12,9 @@ export const load = async ({ params }) => {
if (cachedData) {
output = cachedData;
} else {
+
+ const {apiKey, apiURL} = await parent();
+
const postData = {
ticker: params.tickerID
};
diff --git a/src/routes/fda-calendar/+page.ts b/src/routes/fda-calendar/+page.ts
index edd36d17..8f3232d4 100644
--- a/src/routes/fda-calendar/+page.ts
+++ b/src/routes/fda-calendar/+page.ts
@@ -1,32 +1,18 @@
-import { userRegion, getCache, setCache } from '$lib/store';
+import { getCache, setCache } from '$lib/store';
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-
-userRegion.subscribe(value => {
-
- if (usRegion.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
-
export const load = async ({parent}) => {
const getFDACalendar = async () => {
let output;
- const data = await parent();
const cachedData = getCache('', 'getFDACalendar');
if (cachedData) {
output = cachedData;
} else {
- // make the POST request to the endpoint
+
+ const { apiURL, apiKey, user} = await parent();
+
const response = await fetch(apiURL + '/fda-calendar', {
method: 'GET',
headers: {
@@ -36,7 +22,7 @@ export const load = async ({parent}) => {
output = await response.json();
- output = data?.user?.tier !== 'Pro' ? output?.slice(0,6) : output;
+ output = user?.tier !== 'Pro' ? output?.slice(0,6) : output;
setCache('', output, 'getFDACalendar');
diff --git a/src/routes/heatmaps/+page.ts b/src/routes/heatmaps/+page.ts
index b8525ee2..89cecdc7 100644
--- a/src/routes/heatmaps/+page.ts
+++ b/src/routes/heatmaps/+page.ts
@@ -1,24 +1,12 @@
-import { userRegion, getCache, setCache } from '$lib/store';
-
-
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-
-userRegion.subscribe(value => {
-
- if (usRegion?.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
+import { getCache, setCache } from '$lib/store';
-export const load = async () => {
+
+export const load = async ({parent}) => {
+
+ const { apiURL, apiKey} = await parent();
+
const getSP500HeatMap = async () => {
let output;
diff --git a/src/routes/ipos/+page.ts b/src/routes/ipos/+page.ts
index bf31f1b7..37a30fdb 100644
--- a/src/routes/ipos/+page.ts
+++ b/src/routes/ipos/+page.ts
@@ -11,14 +11,15 @@ export const load = async ({parent, params}) => {
output = cachedData;
} else {
- const data = await parent();
+ const { apiURL, apiKey} = await parent();
+
// make the POST request to the endpoint
const postData = {'year': 'all'};
- const response = await fetch(data?.apiURL + '/ipo-calendar', {
+ const response = await fetch(apiURL + '/ipo-calendar', {
method: 'POST',
headers: {
- "Content-Type": "application/json", "X-API-KEY": data?.apiKey
+ "Content-Type": "application/json", "X-API-KEY": apiKey
},
body: JSON.stringify(postData),
});
diff --git a/src/routes/ipos/[slug]/+page.ts b/src/routes/ipos/[slug]/+page.ts
index fe41572f..6ff92f78 100644
--- a/src/routes/ipos/[slug]/+page.ts
+++ b/src/routes/ipos/[slug]/+page.ts
@@ -10,14 +10,14 @@ export const load = async ({parent, params}) => {
output = cachedData;
} else {
- const data = await parent();
+ const { apiURL, apiKey} = await parent();
// make the POST request to the endpoint
const postData = {'year': params.slug};
- const response = await fetch(data?.apiURL + '/ipo-calendar', {
+ const response = await fetch(apiURL + '/ipo-calendar', {
method: 'POST',
headers: {
- "Content-Type": "application/json", "X-API-KEY": data?.apiKey
+ "Content-Type": "application/json", "X-API-KEY": apiKey
},
body: JSON.stringify(postData),
});
diff --git a/src/routes/market-mover/+page.ts b/src/routes/market-mover/+page.ts
index b45713e0..79b6a776 100644
--- a/src/routes/market-mover/+page.ts
+++ b/src/routes/market-mover/+page.ts
@@ -1,24 +1,12 @@
-import { userRegion, getCache, setCache } from '$lib/store';
-
-
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-
-userRegion.subscribe(value => {
-
- if (usRegion.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
+import { getCache, setCache } from '$lib/store';
-export const load = async () => {
+export const load = async ({parent}) => {
+
+ const { apiURL, apiKey} = await parent();
+
+
const getDailyGainerLoserActive = async () => {
let output;
diff --git a/src/routes/most-retail-volume/+page.ts b/src/routes/most-retail-volume/+page.ts
index 68449679..77919125 100644
--- a/src/routes/most-retail-volume/+page.ts
+++ b/src/routes/most-retail-volume/+page.ts
@@ -1,26 +1,12 @@
-import { userRegion, getCache, setCache } from '$lib/store';
+import { getCache, setCache } from '$lib/store';
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-
-userRegion.subscribe(value => {
-
- if (usRegion.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
-
export const load = async ({parent}) => {
const getMostRetailVolume = async () => {
let output;
- const data = await parent();
+ const {apiKey, apiURL, user} = await parent();
+
const cachedData = getCache('', 'getMostRetailVolume');
if (cachedData) {
@@ -36,7 +22,7 @@ export const load = async ({parent}) => {
output = await response.json();
- output = data?.user?.tier !== 'Pro' ? output?.slice(0,6) : output;
+ output = user?.tier !== 'Pro' ? output?.slice(0,6) : output;
setCache('', output, 'getMostRetailVolume');
diff --git a/src/routes/most-shorted-stocks/+page.ts b/src/routes/most-shorted-stocks/+page.ts
index 7f15d182..ce0a9afd 100644
--- a/src/routes/most-shorted-stocks/+page.ts
+++ b/src/routes/most-shorted-stocks/+page.ts
@@ -1,32 +1,16 @@
-import { userRegion, getCache, setCache } from '$lib/store';
+import { getCache, setCache } from '$lib/store';
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-
-userRegion.subscribe(value => {
-
- if (usRegion.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
-
export const load = async ({parent}) => {
const getMostShortedStocks = async () => {
let output;
- const data = await parent();
+ const {apiKey, apiURL, user} = await parent();
const cachedData = getCache('', 'getMostShortedStocks');
if (cachedData) {
output = cachedData;
} else {
- // make the POST request to the endpoint
const response = await fetch(apiURL + '/most-shorted-stocks', {
method: 'GET',
headers: {
@@ -36,7 +20,7 @@ export const load = async ({parent}) => {
output = await response.json();
- output = data?.user?.tier !== 'Pro' ? output?.slice(0,6) : output;
+ output = user?.tier !== 'Pro' ? output?.slice(0,6) : output;
setCache('', output, 'getMostShortedStocks');
diff --git a/src/routes/notifications/+page.server.ts b/src/routes/notifications/+page.server.ts
index 754b9e32..650e603d 100644
--- a/src/routes/notifications/+page.server.ts
+++ b/src/routes/notifications/+page.server.ts
@@ -1,18 +1,6 @@
import { redirect, error} from '@sveltejs/kit';
-import { userRegion } from '$lib/store';
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
- let fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
-
- userRegion.subscribe(value => {
- if (usRegion.includes(value)) {
- fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
- } else {
- fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
- }
- });
-
export const load = async ({ locals }) => {
if (!locals.pb.authStore.isValid) {
@@ -23,7 +11,7 @@ export const load = async ({ locals }) => {
const postData = {'userId': locals?.user?.id};
- const response = await fetch(fastifyURL+'/get-notifications', {
+ const response = await fetch(locals?.fastifyURL+'/get-notifications', {
method: 'POST',
headers: {
"Content-Type": "application/json"
diff --git a/src/routes/politicians/+page.ts b/src/routes/politicians/+page.ts
index f84d7212..a8c79069 100644
--- a/src/routes/politicians/+page.ts
+++ b/src/routes/politicians/+page.ts
@@ -1,24 +1,8 @@
-import { userRegion, getCache, setCache } from '$lib/store';
+import { getCache, setCache } from '$lib/store';
import defaultAvatar from '$lib/images/senator/default-avatar.png';
import { getPartyForPoliticians } from '$lib/utils';
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-
-userRegion.subscribe(value => {
-
- if (usRegion?.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
-
-
let images = {};
// Function to load images only when they are viewed
@@ -39,7 +23,7 @@ async function loadImages() {
}
-export const load = async () => {
+export const load = async ({parent}) => {
const getAllPolitician = async () => {
let output;
@@ -49,6 +33,9 @@ export const load = async () => {
output = cachedData;
} else {
+ const {apiKey, apiURL} = await parent();
+
+
const response = await fetch(apiURL + '/all-politicians', {
method: 'GET',
headers: {
diff --git a/src/routes/politicians/[slug]/+page.ts b/src/routes/politicians/[slug]/+page.ts
index 6c8132f7..19a37e11 100644
--- a/src/routes/politicians/[slug]/+page.ts
+++ b/src/routes/politicians/[slug]/+page.ts
@@ -1,28 +1,13 @@
-import { userRegion, getCache, setCache } from '$lib/store';
+import { getCache, setCache } from '$lib/store';
import defaultAvatar from '$lib/images/senator/default-avatar.png';
import { getPartyForPoliticians } from '$lib/utils';
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
let images = {};
let politicianImage;
let politicianDistrict;
let politicianCongress;
let politicianParty = 'n/a';
-
-userRegion.subscribe(value => {
-
- if (usRegion?.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
-
-
// Function to load images only when they are viewed
async function loadImages() {
const imageFiles = import.meta.glob('$lib/images/senator/*.png');
@@ -41,7 +26,7 @@ userRegion.subscribe(value => {
}
-export const load = async ({params}) => {
+export const load = async ({parent, params}) => {
const getPolitician = async () => {
let res;
@@ -50,9 +35,10 @@ export const load = async ({params}) => {
if (cachedData) {
res = cachedData;
} else {
+ const { apiURL, apiKey} = await parent();
- const postData = {'politicianId': params.slug}
- // make the POST request to the endpoint
+ const postData = {'politicianId': params.slug}
+
const response = await fetch(apiURL + '/politician-stats', {
method: 'POST',
headers: {
diff --git a/src/routes/politicians/flow-data/+page.ts b/src/routes/politicians/flow-data/+page.ts
index cd52e56d..ea0ee59d 100644
--- a/src/routes/politicians/flow-data/+page.ts
+++ b/src/routes/politicians/flow-data/+page.ts
@@ -1,23 +1,8 @@
-import { userRegion, getCache, setCache } from '$lib/store';
+import { getCache, setCache } from '$lib/store';
import defaultAvatar from '$lib/images/senator/default-avatar.png';
import { getPartyForPoliticians } from '$lib/utils';
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-
-userRegion.subscribe(value => {
-
- if (usRegion?.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
-
let images = {};
// Function to load images only when they are viewed
@@ -38,7 +23,7 @@ async function loadImages() {
}
-export const load = async () => {
+export const load = async ({parent}) => {
const getPoliticianRSS = async () => {
let output;
@@ -48,6 +33,8 @@ export const load = async () => {
output = cachedData;
} else {
+ const {apiKey, apiURL} = await parent();
+
const response = await fetch(apiURL + '/congress-rss-feed', {
method: 'GET',
headers: {
diff --git a/src/routes/price-alert/+page.ts b/src/routes/price-alert/+page.ts
index 7f90044e..74c78f69 100644
--- a/src/routes/price-alert/+page.ts
+++ b/src/routes/price-alert/+page.ts
@@ -1,24 +1,7 @@
-import { userRegion, getCache, setCache } from '$lib/store';
+import { getCache, setCache } from '$lib/store';
-const usRegion = ['cle1','iad1','pdx1','sfo1'];
-
-let apiURL;
-let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
-
-
-userRegion?.subscribe(value => {
-
- if (usRegion?.includes(value)) {
- apiURL = import.meta.env.VITE_USEAST_API_URL;
- } else {
- apiURL = import.meta.env.VITE_EU_API_URL;
- }
-});
-
-
-
-export const load = async () => {
+export const load = async ({parent}) => {
const getMiniPlotsIndex = async () => {
let output;
@@ -28,7 +11,7 @@ export const load = async () => {
if (cachedData) {
output = cachedData;
} else {
-
+ const {apiKey, apiURL} = await parent();
// make the POST request to the endpoint
const response = await fetch(apiURL + '/mini-plots-index', {
method: 'GET',
diff --git a/src/routes/stock-screener/+page.svelte b/src/routes/stock-screener/+page.svelte
index ab86f522..6059ef32 100644
--- a/src/routes/stock-screener/+page.svelte
+++ b/src/routes/stock-screener/+page.svelte
@@ -1,6 +1,6 @@