diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 25f20c64..3df8364e 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -8,14 +8,14 @@ export const handle = async ({ event, resolve }) => { const userRegion = regionHeader.split('::')[0]; const isUsRegion = usRegion.has(userRegion); - const pbUrl = import.meta.env[isUsRegion ? 'VITE_USEAST_POCKETBASE_URL' : 'VITE_EU_POCKETBASE_URL']; + const pbURL = import.meta.env[isUsRegion ? 'VITE_USEAST_POCKETBASE_URL' : 'VITE_EU_POCKETBASE_URL']; const apiURL = import.meta.env[isUsRegion ? 'VITE_USEAST_API_URL' : 'VITE_EU_API_URL']; const fastifyURL = import.meta.env[isUsRegion ? 'VITE_USEAST_FASTIFY_URL' : 'VITE_EU_FASTIFY_URL']; const wsURL = import.meta.env[isUsRegion ? 'VITE_USEAST_WS_URL' : 'VITE_EU_WS_URL']; event.locals = { region: decodeURIComponent(regionHeader), - pb: new PocketBase(pbUrl), + pb: new PocketBase(pbURL), apiURL, fastifyURL, wsURL, diff --git a/src/routes/analysts/+page.ts b/src/routes/analysts/+page.ts index c6fad28c..01d5e96c 100644 --- a/src/routes/analysts/+page.ts +++ b/src/routes/analysts/+page.ts @@ -1,27 +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 ( { parent } ) => { +export const load = async ({parent}) => { const getTopAnalyst = async () => { - const data = await parent() + const { apiURL, apiKey, user} = await parent(); + let output; const cachedData = getCache('', 'getTopAnalyst'); @@ -40,7 +25,7 @@ export const load = async ( { parent } ) => { setCache('', output, 'getTopAnalyst'); } - output = data?.user?.tier !== 'Pro' ? output?.reverse()?.slice(0,6) : output; + output = user?.tier !== 'Pro' ? output?.reverse()?.slice(0,6) : output; return output; }; diff --git a/src/routes/analysts/[slug]/+page.ts b/src/routes/analysts/[slug]/+page.ts index fc21c85a..e658bfda 100644 --- a/src/routes/analysts/[slug]/+page.ts +++ b/src/routes/analysts/[slug]/+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 ({params}) => { +export const load = async ({parent, params}) => { const getAnalystStats = async () => { let output; @@ -28,6 +11,8 @@ export const load = async ({params}) => { output = cachedData; } else { + const { apiURL, apiKey} = await parent(); + const postData = {'analystId': params.slug} // make the POST request to the endpoint const response = await fetch(apiURL + '/analyst-stats', { diff --git a/src/routes/analysts/top-stocks/+page.ts b/src/routes/analysts/top-stocks/+page.ts index 5fa4bf9b..cd93a42c 100644 --- a/src/routes/analysts/top-stocks/+page.ts +++ b/src/routes/analysts/top-stocks/+page.ts @@ -1,33 +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 getTopAnalystStocks = async () => { let output; - const data = await parent(); + const { apiURL, apiKey, user} = await parent(); const cachedData = getCache('', 'getTopAnalystStocks'); if (cachedData) { output = cachedData; } else { - // make the POST request to the endpoint - const response = await fetch(apiURL + '/top-analysts-stocks', { + + const response = await fetch(apiURL + '/top-analysts-stocks', { method: 'GET', headers: { "Content-Type": "application/json", "X-API-KEY": apiKey @@ -40,7 +25,7 @@ export const load = async ({parent}) => { } - output = data?.user?.tier !== 'Pro' ? output?.reverse()?.slice(0,6) : output; + output = user?.tier !== 'Pro' ? output?.reverse()?.slice(0,6) : output; return output; }; diff --git a/src/routes/blog/+page.ts b/src/routes/blog/+page.ts index a65d1df1..14441932 100644 --- a/src/routes/blog/+page.ts +++ b/src/routes/blog/+page.ts @@ -2,10 +2,10 @@ import { pb } from "$lib/pocketbase"; import { getCache, setCache } from '$lib/store'; -export const load = async () => { +export const load = async ({parent}) => { const getAllBlogPost = async () => { let output; - + console.log(await parent()) // Get cached data for the specific tickerID const cachedData = getCache('allBlogPost', 'getAllBlogPost'); if (cachedData) { diff --git a/src/routes/crypto/+page.svelte b/src/routes/crypto/+page.svelte index 228836f4..fe3b04f3 100644 --- a/src/routes/crypto/+page.svelte +++ b/src/routes/crypto/+page.svelte @@ -51,7 +51,6 @@ $: { - @@ -59,7 +58,6 @@ $: { - @@ -74,7 +72,7 @@ $: { --> -
+
diff --git a/src/routes/crypto/+page.ts b/src/routes/crypto/+page.ts index 87849d00..5f53d239 100644 --- a/src/routes/crypto/+page.ts +++ b/src/routes/crypto/+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 getCryptoList = async () => { let output; @@ -27,9 +11,8 @@ export const load = async () => { if (cachedData) { output = cachedData; } else { - - // make the POST request to the endpoint + const {apiKey, apiURL} = await parent(); const response = await fetch(apiURL + '/all-crypto-tickers', { method: 'GET', headers: { diff --git a/src/routes/crypto/[tickerID]/congress-trading/+page.ts b/src/routes/crypto/[tickerID]/congress-trading/+page.ts index afca110a..46f0e27c 100644 --- a/src/routes/crypto/[tickerID]/congress-trading/+page.ts +++ b/src/routes/crypto/[tickerID]/congress-trading/+page.ts @@ -1,24 +1,9 @@ -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 getSenateTrading = async () => { let output; @@ -27,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/crypto/[tickerID]/news/+page.ts b/src/routes/crypto/[tickerID]/news/+page.ts index fe7050e8..38ccdfc8 100644 --- a/src/routes/crypto/[tickerID]/news/+page.ts +++ b/src/routes/crypto/[tickerID]/news/+page.ts @@ -1,23 +1,7 @@ -import { userRegion, getCache, setCache } from '$lib/store'; +import { 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; - } -}); - - - -export const load = async ({ params }) => { +export const load = async ({ parent, params }) => { const getStockNews = async () => { let output; @@ -26,6 +10,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/crypto/[tickerID]/stats/+page.ts b/src/routes/crypto/[tickerID]/stats/+page.ts index df51af88..6522c217 100644 --- a/src/routes/crypto/[tickerID]/stats/+page.ts +++ b/src/routes/crypto/[tickerID]/stats/+page.ts @@ -1,19 +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 ({ params }) => { + +export const load = async ({ parent, params }) => { const getQuantStats = async () => { @@ -24,6 +13,8 @@ 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/dark-pool-flow/+page.ts b/src/routes/dark-pool-flow/+page.ts index eb8a8997..35636712 100644 --- a/src/routes/dark-pool-flow/+page.ts +++ b/src/routes/dark-pool-flow/+page.ts @@ -1,4 +1,4 @@ -import { userRegion, getCache, setCache, isOpen } from '$lib/store'; +import { getCache, setCache, isOpen } from '$lib/store'; const checkMarketHour = async () => { @@ -19,35 +19,18 @@ const checkMarketHour = async () => { } - -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}) => { checkMarketHour() const getDarkPoolFlow = async () => { let output; - const data = await parent(); const cachedData = getCache('', 'getDarkPoolFlow'); if (cachedData) { output = cachedData; } else { - // make the POST request to the endpoint + + const {apiKey, apiURL} = await parent(); const response = await fetch(apiURL + '/dark-pool-flow', { method: 'GET', headers: { diff --git a/src/routes/dividends-calendar/+page.ts b/src/routes/dividends-calendar/+page.ts index 1a6833c2..468161ab 100644 --- a/src/routes/dividends-calendar/+page.ts +++ b/src/routes/dividends-calendar/+page.ts @@ -11,12 +11,12 @@ export const load = async ({parent}) => { output = cachedData; } else { - const data = await parent(); + const {apiKey, apiURL} = await parent(); // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/dividends-calendar', { + const response = await fetch(apiURL + '/dividends-calendar', { method: 'GET', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json", "X-API-KEY": apiKey }, }); diff --git a/src/routes/earnings-calendar/+page.ts b/src/routes/earnings-calendar/+page.ts index e79c9e03..31e6b3b3 100644 --- a/src/routes/earnings-calendar/+page.ts +++ b/src/routes/earnings-calendar/+page.ts @@ -11,12 +11,12 @@ export const load = async ({parent}) => { output = cachedData; } else { - const data = await parent(); + const {apiKey, apiURL} = await parent(); // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/earnings-calendar', { + const response = await fetch(apiURL + '/earnings-calendar', { method: 'GET', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json", "X-API-KEY": apiKey }, }); diff --git a/src/routes/etf/+page.svelte b/src/routes/etf/+page.svelte index 1db77edf..06f471a7 100644 --- a/src/routes/etf/+page.svelte +++ b/src/routes/etf/+page.svelte @@ -3,7 +3,6 @@ import { goto } from '$app/navigation'; import { numberOfUnreadNotification, screenWidth } from '$lib/store'; import { abbreviateNumber } from '$lib/utils'; import { page } from '$app/stores'; -import { fly } from 'svelte/transition'; import logo from '$lib/images/box_logo.png'; import InfiniteLoading from '$lib/components/InfiniteLoading.svelte'; @@ -64,7 +63,6 @@ $: { - @@ -72,12 +70,11 @@ $: { - -
+
-
+
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 @@