From f54cc2f355fa2f8db8fbe389e9307f713467febe Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sat, 27 Jul 2024 01:23:58 +0200 Subject: [PATCH] clean code --- src/hooks.server.ts | 2 + src/routes/+layout.server.ts | 39 ++++------- .../crypto/[tickerID]/+layout.server.ts | 18 +---- src/routes/dividends-calendar/+page.ts | 27 ++----- src/routes/earnings-calendar/+page.ts | 27 ++----- src/routes/economic-calendar/+page.ts | 23 +----- src/routes/etf/[tickerID]/+layout.server.ts | 29 ++------ .../etf/[tickerID]/congress-trading/+page.ts | 26 ++----- src/routes/etf/[tickerID]/dividends/+page.ts | 24 ++----- src/routes/etf/[tickerID]/holdings/+page.ts | 25 ++----- src/routes/etf/[tickerID]/news/+page.ts | 26 ++----- src/routes/hedge-funds/[slug]/+page.ts | 70 +++++-------------- src/routes/ipos/+page.ts | 26 ++----- src/routes/ipos/[slug]/+page.ts | 27 ++----- src/routes/list/amex-stocks/+page.ts | 22 +----- src/routes/options-flow/+page.ts | 27 +------ src/routes/options-zero-dte/+page.ts | 29 ++------ .../stocks/[tickerID]/+layout.server.ts | 14 +--- 18 files changed, 93 insertions(+), 388 deletions(-) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 5e719668..25f20c64 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -11,12 +11,14 @@ export const handle = async ({ event, resolve }) => { 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), apiURL, fastifyURL, + wsURL, apiKey: import.meta.env.VITE_STOCKNEAR_API_KEY }; diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index a718d6b9..9ff4d6dd 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -1,28 +1,13 @@ - export const load = ({ locals, cookies }) => { - - const consent = cookies?.get('cookie-consent') - - if (locals.user) { - return { - user: locals.user, - region: locals.region, - cookieConsent: consent, - apiURL: locals.apiURL, - fastifyURL: locals.fastifyURL, - apiKey: locals.apiKey, - }; - } - - - - return { - user: undefined, - region: locals.region, - cookieConsent: consent, - apiURL: locals.apiURL, - fastifyURL: locals.fastifyURL, - apiKey: locals.apiKey, - }; -}; - + const { user, region, apiURL, fastifyURL, wsURL, apiKey } = locals; + + return { + user: user || undefined, + region, + cookieConsent: cookies?.get('cookie-consent'), + apiURL, + fastifyURL, + wsURL, + apiKey, + }; + }; \ No newline at end of file diff --git a/src/routes/crypto/[tickerID]/+layout.server.ts b/src/routes/crypto/[tickerID]/+layout.server.ts index 9198beea..630f20d4 100644 --- a/src/routes/crypto/[tickerID]/+layout.server.ts +++ b/src/routes/crypto/[tickerID]/+layout.server.ts @@ -1,5 +1,4 @@ -const usRegion = ['cle1','iad1','pdx1','sfo1']; let companyName; @@ -63,20 +62,9 @@ async function fetchPortfolio(fastifyURL, userId) export const load = async ({ params, locals, setHeaders}) => { - const userRegion = locals?.region?.split("::")[0]; - - let apiURL = locals?.apiURL; - let fastifyURL = locals?.fastifyURL; - let apiKey = locals?.apiKey; - let wsURL; - - if (usRegion?.includes(userRegion)) { - wsURL = import.meta.env.VITE_USEAST_WS_URL; - } else { - wsURL = import.meta.env.VITE_EU_WS_URL; - }; - - + let apiURL = locals?.apiURL; + let fastifyURL = locals?.fastifyURL; + let apiKey = locals?.apiKey; const promises = [ fetchData(apiURL,apiKey,'/crypto-profile',params.tickerID), diff --git a/src/routes/dividends-calendar/+page.ts b/src/routes/dividends-calendar/+page.ts index edfd2be5..1a6833c2 100644 --- a/src/routes/dividends-calendar/+page.ts +++ b/src/routes/dividends-calendar/+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 getDividendCalendar = async () => { let output; @@ -28,12 +11,12 @@ export const load = async () => { output = cachedData; } else { - + const data = await parent(); // make the POST request to the endpoint - const response = await fetch(apiURL + '/dividends-calendar', { + const response = await fetch(data?.apiURL + '/dividends-calendar', { method: 'GET', headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json", "X-API-KEY": data?.apiKey }, }); diff --git a/src/routes/earnings-calendar/+page.ts b/src/routes/earnings-calendar/+page.ts index e6c58347..e79c9e03 100644 --- a/src/routes/earnings-calendar/+page.ts +++ b/src/routes/earnings-calendar/+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 getEarningsCalendar = async () => { let output; @@ -28,12 +11,12 @@ export const load = async () => { output = cachedData; } else { - + const data = await parent(); // make the POST request to the endpoint - const response = await fetch(apiURL + '/earnings-calendar', { + const response = await fetch(data?.apiURL + '/earnings-calendar', { method: 'GET', headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json", "X-API-KEY": data?.apiKey }, }); diff --git a/src/routes/economic-calendar/+page.ts b/src/routes/economic-calendar/+page.ts index a57afbb2..3853ecc6 100644 --- a/src/routes/economic-calendar/+page.ts +++ b/src/routes/economic-calendar/+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 getEconomicCalendar = async () => { let output; @@ -28,7 +11,7 @@ export const load = async () => { output = cachedData; } else { - + const { apiURL, apiKey } = await parent(); // make the POST request to the endpoint const response = await fetch(apiURL + '/economic-calendar', { method: 'GET', diff --git a/src/routes/etf/[tickerID]/+layout.server.ts b/src/routes/etf/[tickerID]/+layout.server.ts index f24d5ba0..81ca4ae4 100644 --- a/src/routes/etf/[tickerID]/+layout.server.ts +++ b/src/routes/etf/[tickerID]/+layout.server.ts @@ -1,6 +1,3 @@ - -const usRegion = ['cle1','iad1','pdx1','sfo1']; - let companyName; @@ -88,28 +85,10 @@ async function fetchPortfolio(fastifyURL, userId) export const load = async ({ params, locals, setHeaders}) => { - const userRegion = locals?.region?.split("::")[0]; - - let apiURL = locals?.apiURL; - let fastifyURL = locals?.fastifyURL; - let apiKey = locals?.apiKey; - let wsURL; - - if (usRegion?.includes(userRegion)) { - wsURL = import.meta.env.VITE_USEAST_WS_URL; - } else { - wsURL = import.meta.env.VITE_EU_WS_URL; - }; - - if (usRegion?.includes(userRegion)) { - apiURL = import.meta.env.VITE_USEAST_API_URL; - fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL; - } else { - apiURL = import.meta.env.VITE_EU_API_URL; - fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL; - }; - - + let apiURL = locals?.apiURL; + let fastifyURL = locals?.fastifyURL; + let apiKey = locals?.apiKey; + let wsURL = locals?.wsURL; const promises = [ diff --git a/src/routes/etf/[tickerID]/congress-trading/+page.ts b/src/routes/etf/[tickerID]/congress-trading/+page.ts index afca110a..3d61f5a9 100644 --- a/src/routes/etf/[tickerID]/congress-trading/+page.ts +++ b/src/routes/etf/[tickerID]/congress-trading/+page.ts @@ -1,24 +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; +import { getCache, setCache } from '$lib/store'; -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 getSenateTrading = async () => { let output; @@ -27,15 +10,16 @@ export const load = async ({ params }) => { if (cachedData) { output = cachedData; } else { + const data = await parent(); const postData = { ticker: params.tickerID }; // make the POST request to the endpoint - const response = await fetch(apiURL + '/congress-trading-ticker', { + const response = await fetch(data?.apiURL + '/congress-trading-ticker', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json", "X-API-KEY": data?.apiKey }, body: JSON.stringify(postData) }); diff --git a/src/routes/etf/[tickerID]/dividends/+page.ts b/src/routes/etf/[tickerID]/dividends/+page.ts index d3e6eeb5..f1d4df5e 100644 --- a/src/routes/etf/[tickerID]/dividends/+page.ts +++ b/src/routes/etf/[tickerID]/dividends/+page.ts @@ -1,22 +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 getStockDividend = async () => { let newsList; @@ -25,15 +10,16 @@ export const load = async ({ params }) => { if (cachedData) { newsList = cachedData; } else { + const data = await parent(); const postData = { ticker: params.tickerID }; // make the POST request to the endpoint - const response = await fetch(apiURL + '/stock-dividend', { + const response = await fetch(data?.apiURL + '/stock-dividend', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json", "X-API-KEY": data?.apiKey }, body: JSON.stringify(postData) }); diff --git a/src/routes/etf/[tickerID]/holdings/+page.ts b/src/routes/etf/[tickerID]/holdings/+page.ts index b2fc00cc..1e887561 100644 --- a/src/routes/etf/[tickerID]/holdings/+page.ts +++ b/src/routes/etf/[tickerID]/holdings/+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 ({ params }) => { +export const load = async ({ parent, params }) => { const getETFHoldings = async () => { let output; @@ -27,15 +11,16 @@ export const load = async ({ params }) => { if (cachedData) { output = cachedData; } else { + const data = await parent(); const postData = { ticker: params.tickerID }; // make the POST request to the endpoint - const response = await fetch(apiURL + '/etf-holdings', { + const response = await fetch(data?.apiURL + '/etf-holdings', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json", "X-API-KEY": data?.apiKey }, body: JSON.stringify(postData) }); diff --git a/src/routes/etf/[tickerID]/news/+page.ts b/src/routes/etf/[tickerID]/news/+page.ts index 4dab539e..6c33e180 100644 --- a/src/routes/etf/[tickerID]/news/+page.ts +++ b/src/routes/etf/[tickerID]/news/+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 getStockNews = async () => { let output; @@ -27,15 +10,16 @@ export const load = async ({ params }) => { if (cachedData) { output = cachedData; } else { + const data = await parent(); const postData = { ticker: params.tickerID }; // make the POST request to the endpoint - const response = await fetch(apiURL + '/stock-news', { + const response = await fetch(data?.apiURL + '/stock-news', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json", "X-API-KEY": data?.apiKey }, body: JSON.stringify(postData) }); diff --git a/src/routes/hedge-funds/[slug]/+page.ts b/src/routes/hedge-funds/[slug]/+page.ts index 24ddcc23..eeb27af9 100644 --- a/src/routes/hedge-funds/[slug]/+page.ts +++ b/src/routes/hedge-funds/[slug]/+page.ts @@ -1,65 +1,31 @@ -import { userRegion, displayCompanyName, 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 }) => { +import { displayCompanyName, getCache, setCache } from '$lib/store'; +export const load = async ({ parent, params }) => { const getHedgeFundsData = async () => { - let output; - - // Get cached data for the specific tickerID const cachedData = getCache(params.slug, 'getHedgeFundsData'); - if (cachedData) { - output = cachedData; - } - else { + if (cachedData) return cachedData; - - const postData = { - cik: params.slug - }; + const { apiURL, apiKey } = await parent(); + const response = await fetch(apiURL+'/cik-data', { + method: 'POST', + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey + }, + body: JSON.stringify({ cik: params.slug }) + }); - // make the POST request to the endpoint - const response = await fetch(apiURL + '/cik-data', { - method: 'POST', - headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey - }, - body: JSON.stringify(postData) - }); + const output = await response.json(); - output = await response.json(); + if (output?.holdings) { + output.holdings = output?.holdings?.filter(item => item?.sharesNumber && item?.symbol); + } - // Cache the data for this specific tickerID with a specific name 'getHedgeFundsData' - try { - output.holdings = output?.holdings?.filter(item => item?.sharesNumber !== 0 && item?.symbol !== null); //item?.symbol !== null - } catch(e) { - console.log(e) - } - - setCache(params.slug, output, 'getHedgeFundsData'); - } - - - - displayCompanyName.update(value => output?.name ?? params.slug) + setCache(params.slug, output, 'getHedgeFundsData'); + displayCompanyName.update(() => output?.name ?? params.slug); return output; }; - // Make sure to return a promise return { getHedgeFundsData: await getHedgeFundsData() }; diff --git a/src/routes/ipos/+page.ts b/src/routes/ipos/+page.ts index 4be2a4b7..bf31f1b7 100644 --- a/src/routes/ipos/+page.ts +++ b/src/routes/ipos/+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 getIPOCalendar = async () => { let output; @@ -28,13 +11,14 @@ export const load = async ({params}) => { output = cachedData; } else { + const data = await parent(); // make the POST request to the endpoint const postData = {'year': 'all'}; - const response = await fetch(apiURL + '/ipo-calendar', { + const response = await fetch(data?.apiURL + '/ipo-calendar', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json", "X-API-KEY": data?.apiKey }, body: JSON.stringify(postData), }); diff --git a/src/routes/ipos/[slug]/+page.ts b/src/routes/ipos/[slug]/+page.ts index 0131ca4a..fe41572f 100644 --- a/src/routes/ipos/[slug]/+page.ts +++ b/src/routes/ipos/[slug]/+page.ts @@ -1,24 +1,6 @@ -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 getIPOCalendar = async () => { let output; @@ -28,13 +10,14 @@ export const load = async ({params}) => { output = cachedData; } else { + const data = await parent(); // make the POST request to the endpoint const postData = {'year': params.slug}; - const response = await fetch(apiURL + '/ipo-calendar', { + const response = await fetch(data?.apiURL + '/ipo-calendar', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json", "X-API-KEY": data?.apiKey }, body: JSON.stringify(postData), }); diff --git a/src/routes/list/amex-stocks/+page.ts b/src/routes/list/amex-stocks/+page.ts index 176248a1..a4869fab 100644 --- a/src/routes/list/amex-stocks/+page.ts +++ b/src/routes/list/amex-stocks/+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 getAmexStocks = async () => { let output; @@ -28,6 +11,7 @@ export const load = async () => { output = cachedData; } else { + const { apiURL, apiKey} = await parent(); const postData = {'filterList': 'amex'} const response = await fetch(apiURL + '/filter-stock-list', { diff --git a/src/routes/options-flow/+page.ts b/src/routes/options-flow/+page.ts index c77145c5..3e63fab1 100644 --- a/src/routes/options-flow/+page.ts +++ b/src/routes/options-flow/+page.ts @@ -1,4 +1,4 @@ -import { userRegion, isOpen} from '$lib/store'; +import { isOpen} from '$lib/store'; const checkMarketHour = async () => { @@ -19,30 +19,10 @@ const checkMarketHour = async () => { } -const usRegion = ['cle1','iad1','pdx1','sfo1']; -let apiURL; -let wsURL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - - -userRegion.subscribe(value => { - - if (usRegion?.includes(value)) { - apiURL = import.meta.env.VITE_USEAST_API_URL; - wsURL = import.meta.env.VITE_USEAST_WS_URL; - } else { - apiURL = import.meta.env.VITE_EU_API_URL; - wsURL = import.meta.env.VITE_EU_WS_URL; - } -}); - - - - - -export const load = async () => { +export const load = async ({parent}) => { await checkMarketHour(); + const { apiURL, apiKey} = await parent(); const getOptionsFlowFeed = async () => { // make the POST request to the endpoint @@ -60,6 +40,5 @@ export const load = async () => { // Make sure to return a promise return { getOptionsFlowFeed: await getOptionsFlowFeed(), - wsURL, }; }; \ No newline at end of file diff --git a/src/routes/options-zero-dte/+page.ts b/src/routes/options-zero-dte/+page.ts index 7753c494..9371f0d5 100644 --- a/src/routes/options-zero-dte/+page.ts +++ b/src/routes/options-zero-dte/+page.ts @@ -1,4 +1,4 @@ -import { userRegion, isOpen} from '$lib/store'; +import {isOpen} from '$lib/store'; const checkMarketHour = async () => { @@ -19,31 +19,10 @@ const checkMarketHour = async () => { } -const usRegion = ['cle1','iad1','pdx1','sfo1']; - -let apiURL; -let wsURL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - - -userRegion.subscribe(value => { - - if (usRegion?.includes(value)) { - apiURL = import.meta.env.VITE_USEAST_API_URL; - wsURL = import.meta.env.VITE_USEAST_WS_URL; - } else { - apiURL = import.meta.env.VITE_EU_API_URL; - wsURL = import.meta.env.VITE_EU_WS_URL; - } -}); - - - - - -export const load = async () => { +export const load = async ({parent}) => { await checkMarketHour(); - + const { apiURL, apiKey } = await parent(); + const getOptionsZeroDTE = async () => { // make the POST request to the endpoint const response = await fetch(apiURL + '/options-zero-dte', { diff --git a/src/routes/stocks/[tickerID]/+layout.server.ts b/src/routes/stocks/[tickerID]/+layout.server.ts index 3a158178..2354fe6f 100644 --- a/src/routes/stocks/[tickerID]/+layout.server.ts +++ b/src/routes/stocks/[tickerID]/+layout.server.ts @@ -1,6 +1,4 @@ -const usRegion = ['cle1','iad1','pdx1','sfo1']; - let companyName; function cleanString(input) { @@ -117,22 +115,12 @@ async function fetchCommunitySentiment(pb, ticker, cookies) export const load = async ({ params, locals, cookies, setHeaders}) => { - const userRegion = locals?.region?.split("::")[0]; - let apiURL = locals?.apiURL; let fastifyURL = locals?.fastifyURL; let apiKey = locals?.apiKey; - let wsURL; + let wsURL = locals?.wsURL; - if (usRegion?.includes(userRegion)) { - wsURL = import.meta.env.VITE_USEAST_WS_URL; - } else { - wsURL = import.meta.env.VITE_EU_WS_URL; - }; - - - const promises = [ fetchData(apiURL,apiKey, '/similar-stocks',params.tickerID), fetchData(apiURL,apiKey, '/stockdeck',params.tickerID),