diff --git a/src/lib/components/AddPortfolio.svelte b/src/lib/components/AddPortfolio.svelte index a41a4b4c..e83ec9c6 100644 --- a/src/lib/components/AddPortfolio.svelte +++ b/src/lib/components/AddPortfolio.svelte @@ -15,7 +15,7 @@ async function createPortfolio(event) { const postData = {'userId': data?.user?.id} - const response = await fetch(data?.fastifyURL+'/create-portfolio', { + const response = await fetch('/api/create-portfolio', { method: 'POST', headers: { "Content-Type": "application/json" diff --git a/src/lib/components/BuyTrade.svelte b/src/lib/components/BuyTrade.svelte deleted file mode 100644 index 574617a5..00000000 --- a/src/lib/components/BuyTrade.svelte +++ /dev/null @@ -1,521 +0,0 @@ - - - - - - - {#if $screenWidth >= 640} - - - - - - - - - - - - - - - - {:else} - - - -
- - -
- - - -
-
- - {/if} \ No newline at end of file diff --git a/src/lib/components/CommentSection.svelte b/src/lib/components/CommentSection.svelte index d42fc319..a672d1ff 100644 --- a/src/lib/components/CommentSection.svelte +++ b/src/lib/components/CommentSection.svelte @@ -99,6 +99,7 @@ const handleUpvote = async (event) => { 'postId': postId, 'commentId': commentId, 'userId': data?.user?.id, + 'path': 'upvote-comment' }; upvoteButtonClicked = !upvoteButtonClicked; @@ -115,7 +116,7 @@ const handleUpvote = async (event) => { } else { upvoteCounter--; } - const response = await fetch(data?.fastifyURL+'/upvote-comment', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -133,6 +134,7 @@ const handleDownvote = async (event) => { const postData = { 'commentId': commentId, 'userId': data?.user?.id, + 'path': 'downvote-comment' }; downvoteButtonClicked = !downvoteButtonClicked; @@ -151,7 +153,7 @@ const handleDownvote = async (event) => { } - const response = await fetch(data?.fastifyURL+'/downvote-comment', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -184,12 +186,13 @@ const handleDownvote = async (event) => { const postData = { 'userId': data?.user?.id, 'commentId': comment?.id, - 'commentUser': comment?.user + 'commentUser': comment?.user, + 'path': 'delete-comment' } - const response = await fetch(data?.fastifyURL+'/delete-comment', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" diff --git a/src/lib/components/Feedback.svelte b/src/lib/components/Feedback.svelte index 6a24415a..d1c29e02 100644 --- a/src/lib/components/Feedback.svelte +++ b/src/lib/components/Feedback.svelte @@ -48,7 +48,7 @@ 'description': inputValue}; - const response = await fetch(data?.fastifyURL+'/feedback', { + const response = await fetch('/api/feedback', { method: 'POST', headers: { "Content-Type": "application/json" diff --git a/src/lib/components/PostSection.svelte b/src/lib/components/PostSection.svelte index c0285aa8..cabda05f 100644 --- a/src/lib/components/PostSection.svelte +++ b/src/lib/components/PostSection.svelte @@ -71,10 +71,11 @@ const postData = {'postId': posts?.id, - 'userId': posts?.user + 'userId': posts?.user, + 'path': 'delete-post', }; - const response = await fetch(data?.fastifyURL+'/delete-post', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -113,6 +114,7 @@ const handleUpvote = async (event) => { const postData = { 'postId': postId, 'userId': data?.user?.id, + 'path': 'upvote', }; upvoteButtonClicked[postId] = !upvoteButtonClicked[postId]; @@ -132,7 +134,7 @@ const handleUpvote = async (event) => { $postVote = {'id': postId, 'upvote': upvoteCounter[postId], 'downvote': downvoteCounter[postId], 'upvoteClicked': upvoteButtonClicked[postId], 'downvoteClicked': downvoteButtonClicked[postId]}; - const response = await fetch(data?.fastifyURL+'/upvote', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -149,6 +151,7 @@ const handleDownvote = async (event) => { const postData = { 'postId': postId, 'userId': data?.user?.id, + 'path': 'downvote', }; downvoteButtonClicked[postId] = !downvoteButtonClicked[postId]; @@ -168,7 +171,7 @@ const handleDownvote = async (event) => { $postVote = {'id': postId, 'upvote': upvoteCounter[postId], 'downvote': downvoteCounter[postId], 'upvoteClicked': upvoteButtonClicked[postId], 'downvoteClicked': downvoteButtonClicked[postId]}; - const response = await fetch(data?.fastifyURL+'/downvote', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { 'Content-Type': 'application/json' diff --git a/src/lib/components/PriceAlert.svelte b/src/lib/components/PriceAlert.svelte index 5a0163a5..fc07bd57 100644 --- a/src/lib/components/PriceAlert.svelte +++ b/src/lib/components/PriceAlert.svelte @@ -30,10 +30,11 @@ 'priceWhenCreated': currentPrice?.toFixed(2), 'condition': values?.at(0) < 0 ? 'below' : 'above', 'targetPrice': displayPrice, + 'path': 'create-price-alert' } // Make the POST request to the endpoint - const response = await fetch(data?.fastifyURL+'/create-price-alert', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" diff --git a/src/lib/components/SellTrade.svelte b/src/lib/components/SellTrade.svelte deleted file mode 100644 index 2fc75524..00000000 --- a/src/lib/components/SellTrade.svelte +++ /dev/null @@ -1,492 +0,0 @@ - - - - - - - -{#if $screenWidth >=640} - - - - - - - - - - - - -{:else} - - - -
- - -
- - - -
- -
- -{/if} \ No newline at end of file diff --git a/src/lib/tracker.ts b/src/lib/tracker.ts deleted file mode 100644 index a9359869..00000000 --- a/src/lib/tracker.ts +++ /dev/null @@ -1,83 +0,0 @@ -let fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL; //import.meta.env.VITE_EU_FASTIFY_URL; - -export const trackPageVisit = async (path, userAgent) => { - const postData = { - type: "trackPageVisit", - path: path, - userAgent: userAgent, - }; - - const response = await fetch(fastifyURL + "/mixpanel", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(postData), - }); -}; - -export const trackPageDuration = async (path, userAgent, time) => { - const postData = { - type: "trackPageDuration", - path: path, - time: time, - userAgent: userAgent, - }; - - const response = await fetch(fastifyURL + "/mixpanel", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(postData), - }); -}; - -export const trackPageError = async (path, userAgent, status, message) => { - const postData = { - type: "trackPageError", - path: path, - status: status, - message: message, - userAgent: userAgent, - }; - - const response = await fetch(fastifyURL + "/mixpanel", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(postData), - }); -}; - -export const trackAsset = async (symbol, assetType) => { - const postData = { - type: "trackAsset", - symbol: symbol, - assetType: assetType, - }; - - const response = await fetch(fastifyURL + "/mixpanel", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(postData), - }); -}; - -export const trackButtonClick = async (name) => { - const postData = { - type: "trackButton", - name: name, - }; - - const response = await fetch(fastifyURL + "/mixpanel", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(postData), - }); -}; diff --git a/src/lib/workers/notificationWorker.ts b/src/lib/workers/notificationWorker.ts index c0ba878b..16711c6b 100644 --- a/src/lib/workers/notificationWorker.ts +++ b/src/lib/workers/notificationWorker.ts @@ -1,9 +1,9 @@ // lib/workers/test.ts -async function loadNotifications(fastifyURL: string, userId: string) { +async function loadNotifications(userId: string) { const postData = { userId: userId }; - const response = await fetch(fastifyURL + "/get-notifications", { + const response = await fetch("/api/get-notifications", { method: "POST", headers: { "Content-Type": "application/json", @@ -17,12 +17,9 @@ async function loadNotifications(fastifyURL: string, userId: string) { onmessage = async (event: MessageEvent) => { const data = event.data?.message; - const fastifyURL = data?.fastifyURL; const userId = data?.userId; try { - const [notificationList] = await Promise.all([ - loadNotifications(fastifyURL, userId), - ]); + const [notificationList] = await Promise.all([loadNotifications(userId)]); const numberOfUnreadNotification = notificationList?.length; const hasUnreadElement = notificationList?.length !== 0 ? true : false; diff --git a/src/lib/workers/twitchStatusWorker.ts b/src/lib/workers/twitchStatusWorker.ts deleted file mode 100644 index 72663761..00000000 --- a/src/lib/workers/twitchStatusWorker.ts +++ /dev/null @@ -1,30 +0,0 @@ -async function loadTwitchStatus(fastifyURL: string) { - // make the GET request to the endpoint - const response = await fetch(fastifyURL + "/get-twitch-status", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - const output = (await response.json())?.items; - return output; -} - -onmessage = async (event: MessageEvent) => { - const data = event.data?.message; - const fastifyURL = data?.fastifyURL; - try { - const twitchStatus = await loadTwitchStatus(fastifyURL); - const output = { twitchStatus }; - - postMessage({ message: "success", output }); - } catch (e) { - postMessage({ message: "error", e }); - } - // Sending data back to the main thread - //postMessage({ message: 'Data received in the worker', ticker, apiURL }); -}; - -export {}; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 7ee324e4..9ebfdda0 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -132,7 +132,7 @@ const loadWorker = async () => { if ('serviceWorker' in navigator) { const SyncWorker = await import('$lib/workers/notificationWorker?worker'); syncWorker = new SyncWorker.default(); - syncWorker.postMessage({ message: {'fastifyURL': data?.fastifyURL, 'userId': data?.user?.id }}); + syncWorker.postMessage({ message: {'userId': data?.user?.id }}); syncWorker.onmessage = handleMessage; } else { // Fallback logic here @@ -147,7 +147,7 @@ async function fallbackWorker() { console.log('Fallback worker activated'); const postData = {'userId': data?.user?.id}; - const response = await fetch(data?.fastifyURL+'/get-notifications', { + const response = await fetch('/api/get-notifications', { method: 'POST', headers: { "Content-Type": "application/json" @@ -162,17 +162,6 @@ async function fallbackWorker() { } -/* -const loadTwitchWorker = async () => { - -const SyncWorker = await import('$lib/workers/twitchStatusWorker?worker'); -syncWorker = new SyncWorker.default(); - -syncWorker.postMessage({ message: {'fastifyURL': fastifyURL }}); -syncWorker.onmessage = handleTwitchMessage; - -}; -*/ let Cookie; $showCookieConsent = typeof data?.cookieConsent !== 'undefined' ? false : true; diff --git a/src/routes/api/fastify-post-data/+server.ts b/src/routes/api/fastify-post-data/+server.ts new file mode 100644 index 00000000..9d31b7b2 --- /dev/null +++ b/src/routes/api/fastify-post-data/+server.ts @@ -0,0 +1,21 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { fastifyURL } = locals; + + // Destructure 'path' from data and collect the rest + const { path, ...restData } = data; + + const response = await fetch(`${fastifyURL}/${path}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + // Pass the rest of the data (excluding path) in the body + body: JSON.stringify(restData), + }); + + const output = await response.json(); + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/feedback/+server.ts b/src/routes/api/feedback/+server.ts new file mode 100644 index 00000000..826770ac --- /dev/null +++ b/src/routes/api/feedback/+server.ts @@ -0,0 +1,18 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { fastifyURL } = locals; + + const response = await fetch(fastifyURL + "/feedback", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/get-all-comments/+server.ts b/src/routes/api/get-all-comments/+server.ts new file mode 100644 index 00000000..0b656fd5 --- /dev/null +++ b/src/routes/api/get-all-comments/+server.ts @@ -0,0 +1,18 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { fastifyURL } = locals; + + const response = await fetch(fastifyURL + "/get-all-comments", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/get-community-stats/+server.ts b/src/routes/api/get-community-stats/+server.ts new file mode 100644 index 00000000..a25c0e35 --- /dev/null +++ b/src/routes/api/get-community-stats/+server.ts @@ -0,0 +1,16 @@ +import type { RequestHandler } from "./$types"; + +export const GET: RequestHandler = async ({ locals }) => { + const { fastifyURL } = locals; + + const response = await fetch(fastifyURL + "/get-community-stats", { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/get-moderators/+server.ts b/src/routes/api/get-moderators/+server.ts new file mode 100644 index 00000000..3a9560ca --- /dev/null +++ b/src/routes/api/get-moderators/+server.ts @@ -0,0 +1,16 @@ +import type { RequestHandler } from "./$types"; + +export const GET: RequestHandler = async ({ locals }) => { + const { fastifyURL } = locals; + + const response = await fetch(fastifyURL + "/get-moderators", { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/get-notifications/+server.ts b/src/routes/api/get-notifications/+server.ts new file mode 100644 index 00000000..9bea99c8 --- /dev/null +++ b/src/routes/api/get-notifications/+server.ts @@ -0,0 +1,18 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { fastifyURL } = locals; + + const response = await fetch(fastifyURL + "/get-notifications", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/get-one-post/+server.ts b/src/routes/api/get-one-post/+server.ts new file mode 100644 index 00000000..52c39e69 --- /dev/null +++ b/src/routes/api/get-one-post/+server.ts @@ -0,0 +1,18 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { fastifyURL } = locals; + + const response = await fetch(fastifyURL + "/get-one-post", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/get-post/+server.ts b/src/routes/api/get-post/+server.ts new file mode 100644 index 00000000..29adfaef --- /dev/null +++ b/src/routes/api/get-post/+server.ts @@ -0,0 +1,18 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { fastifyURL } = locals; + + const response = await fetch(fastifyURL + "/get-post", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/community/+page.svelte b/src/routes/community/+page.svelte index 3e5bad59..2097b9eb 100644 --- a/src/routes/community/+page.svelte +++ b/src/routes/community/+page.svelte @@ -23,7 +23,6 @@ let moderators ; let communityStats; let discordData = []; - let tickerMentioning = []; let posts = null; @@ -73,8 +72,7 @@ const getModerators = async () => { output = cachedData; } else { - // make the POST request to the endpoint - const response = await fetch(data?.fastifyURL + '/get-moderators', { + const response = await fetch('/api/get-moderators', { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -89,32 +87,7 @@ const getModerators = async () => { return output; }; -/* -const getTickerMentioning = async () => { - let output; - // Get cached data for the specific tickerID - const cachedData = getCache('', 'getTickerMentioning'); - if (cachedData) { - output = cachedData; - } else { - - // make the POST request to the endpoint - const response = await fetch(apiURL + '/ticker-mentioning', { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }); - - output = await response.json(); - - setCache('', output, 'getTickerMentioning'); - } - - return output; -}; -*/ const getCommunityStats = async () => { let output; @@ -124,8 +97,7 @@ const getCommunityStats = async () => { output = cachedData; } else { - // make the POST request to the endpoint - const response = await fetch(data?.fastifyURL + '/get-community-stats', { + const response = await fetch('/api/get-community-stats', { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -167,7 +139,7 @@ async function getPost() { } // Make the POST request to the endpoint - const response = await fetch(data?.fastifyURL+'/get-post', { + const response = await fetch('/api/get-post', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/routes/community/post/[postId]/+page.svelte b/src/routes/community/post/[postId]/+page.svelte index e3c00aed..f53b2b84 100644 --- a/src/routes/community/post/[postId]/+page.svelte +++ b/src/routes/community/post/[postId]/+page.svelte @@ -39,6 +39,7 @@ const postData = { 'postId': postId, 'userId': data?.user?.id, + 'path': 'upvote', }; upvoteButtonClicked[postId] = !upvoteButtonClicked[postId]; @@ -58,7 +59,7 @@ $postVote = {'id': postId, 'upvote': upvoteCounter[postId], 'downvote': downvoteCounter[postId], 'upvoteClicked': upvoteButtonClicked[postId], 'downvoteClicked': downvoteButtonClicked[postId]}; - const response = await fetch(data?.fastifyURL+'/upvote', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -75,6 +76,7 @@ const postData = { 'postId': postId, 'userId': data?.user?.id, + 'path': 'downvote', }; downvoteButtonClicked[postId] = !downvoteButtonClicked[postId]; @@ -94,7 +96,7 @@ $postVote = {'id': postId, 'upvote': upvoteCounter[postId], 'downvote': downvoteCounter[postId], 'upvoteClicked': upvoteButtonClicked[postId], 'downvoteClicked': downvoteButtonClicked[postId]}; - const response = await fetch(data?.fastifyURL+'/downvote', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -153,10 +155,11 @@ const postData = { postId: data?.getPostId, - userId: data?.user?.id + userId: data?.user?.id, + path: 'delete-post' }; - const response = await fetch(data?.fastifyURL+'/delete-post', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -207,7 +210,7 @@ const postData = {'postId': data?.getPostId}; // make the GET request to the endpoint - const response = await fetch(data?.fastifyURL+'/get-all-comments', { + const response = await fetch('/api/get-all-comments', { method: 'POST', headers: { "Content-Type": "application/json" @@ -232,7 +235,7 @@ } else { // make the POST request to the endpoint - const response = await fetch(data?.fastifyURL + '/get-moderators', { + const response = await fetch('/api/get-moderators', { method: 'GET', headers: { "Content-Type": "application/json" diff --git a/src/routes/community/post/[postId]/+page.ts b/src/routes/community/post/[postId]/+page.ts index 8085e16e..d6cefa3d 100644 --- a/src/routes/community/post/[postId]/+page.ts +++ b/src/routes/community/post/[postId]/+page.ts @@ -2,7 +2,7 @@ import { cachedPosts } from "$lib/store"; import { get } from "svelte/store"; -export const load = async ({ parent, params }) => { +export const load = async ({ params, fetch }) => { async function getOnePost() { // Get the current value of cachedPosts const cachedValue = get(cachedPosts); @@ -12,15 +12,14 @@ export const load = async ({ parent, params }) => { cachedValue?.posts?.find((item) => item?.id === params.postId) ?? {}; // If the post is found in the cache, return it - if (Object.keys(output).length !== 0) { + if (Object?.keys(output)?.length !== 0) { return output; } - const { fastifyURL } = await parent(); // If the post is not found in the cache, fetch it from the endpoint const postData = { postId: params.postId }; - const response = await fetch(fastifyURL + "/get-one-post", { + const response = await fetch("/api/get-one-post", { method: "POST", headers: { "Content-Type": "application/json", @@ -31,7 +30,7 @@ export const load = async ({ parent, params }) => { const result = await response.json(); // Assuming the result contains an 'items' array - return result.items; + return result?.items; } const getPostId = async () => { diff --git a/src/routes/community/profile/+page.svelte b/src/routes/community/profile/+page.svelte index f179d441..5d42d255 100644 --- a/src/routes/community/profile/+page.svelte +++ b/src/routes/community/profile/+page.svelte @@ -339,7 +339,7 @@ const getModerators = async () => { } else { // make the POST request to the endpoint - const response = await fetch(data?.fastifyURL + '/get-moderators', { + const response = await fetch('/api/get-moderators', { method: 'GET', headers: { "Content-Type": "application/json" @@ -370,10 +370,10 @@ const getUserStats = async () => { output = cachedData; } else { - const postData = {'userId': data?.user?.id}; + const postData = {'userId': data?.user?.id, 'path': 'get-user-stats'}; // make the POST request to the endpoint - const response = await fetch(data?.fastifyURL + '/get-user-stats', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -437,10 +437,11 @@ async function getPost() { startPage: currentPage, seenPostId: seenPostId.length === 0 ? [] : seenPostId, userId: data?.user?.id, + path: 'get-post', }; // Make the POST request to the endpoint - const response = await fetch(data?.fastifyURL+'/get-post', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" diff --git a/src/routes/community/user/[userId]/+page.svelte b/src/routes/community/user/[userId]/+page.svelte index 372e87fb..e6e9abd1 100644 --- a/src/routes/community/user/[userId]/+page.svelte +++ b/src/routes/community/user/[userId]/+page.svelte @@ -42,9 +42,9 @@ let noPostMore = false; const getUserData = async() => { - const postData = {'userId': data?.userId}; + const postData = {'userId': data?.userId, 'path': 'get-user-data'}; - const response = await fetch(data?.fastifyURL+'/get-user-data', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -93,10 +93,10 @@ const getUserStats = async () => { output = cachedData; } else { - const postData = {'userId': data?.userId}; + const postData = {'userId': data?.userId, 'path': 'get-user-stats'}; // make the POST request to the endpoint - const response = await fetch(data?.fastifyURL + '/get-user-stats', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -123,8 +123,7 @@ const getModerators = async () => { output = cachedData; } else { - // make the POST request to the endpoint - const response = await fetch(data?.fastifyURL + '/get-moderators', { + const response = await fetch('/api/get-moderators', { method: 'GET', headers: { "Content-Type": "application/json" @@ -155,10 +154,11 @@ async function getPost() { startPage: currentPage, seenPostId: seenPostId.length === 0 ? [] : seenPostId, userId: data?.userId, + path: 'get-post' }; // Make the POST request to the endpoint - const response = await fetch(data?.fastifyURL+'/get-post', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" diff --git a/src/routes/crypto/[tickerID]/+layout.svelte b/src/routes/crypto/[tickerID]/+layout.svelte index 5725f9f0..1ea53c77 100644 --- a/src/routes/crypto/[tickerID]/+layout.svelte +++ b/src/routes/crypto/[tickerID]/+layout.svelte @@ -50,7 +50,6 @@ async function loadSearchData() { let userWatchList = data?.getUserWatchlist ?? []; let isTickerIncluded; - let userPortfolio = data?.getUserPortfolio ?? []; let holdingShares = 0; let availableCash = 0; @@ -155,9 +154,10 @@ async function toggleUserWatchlist(watchListId: string) { 'userId': data?.user?.id, 'watchListId': watchListId, 'ticker': $cryptoTicker, + 'path': 'update-watchlist' }; - const response = await fetch(data?.fastifyURL + '/update-watchlist', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -188,23 +188,7 @@ async function toggleUserWatchlist(watchListId: string) { } -async function fetchPortfolio() -{ - const postData = {'userId': data?.user?.id}; - const response = await fetch(data?.fastifyURL+'/get-portfolio-data', { - method: 'POST', - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify(postData) - }); - - userPortfolio = (await response.json())?.items; - -} - - @@ -280,10 +264,7 @@ async function websocketRealtimeData() { let LoginPopup; -let BuyTrade; -let SellTrade; let PriceAlert; -let AddPortfolio; onMount(async () => { @@ -390,27 +371,11 @@ $: { } } -$: { - if(userPortfolio) { - availableCash = userPortfolio?.at(0)?.availableCash; - const userHoldingList = userPortfolio?.at(0)?.holdings || []; - const stockIndex = userHoldingList?.findIndex(stock => stock?.symbol === $cryptoTicker); - if (stockIndex !== -1) - { - - holdingShares = userHoldingList[stockIndex]['numberOfShares']; - } - else { - holdingShares = 0; - } - } -} $: { if(typeof window !== 'undefined' && $traded && data?.user && $cryptoTicker?.length !== 0) { - fetchPortfolio(); $traded = false; } } diff --git a/src/routes/dark-pool-flow/+page.svelte b/src/routes/dark-pool-flow/+page.svelte deleted file mode 100644 index d1650c9e..00000000 --- a/src/routes/dark-pool-flow/+page.svelte +++ /dev/null @@ -1,572 +0,0 @@ - - - - - - - - - - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} Dark Pool Flow Β· stocknear - - - - - - - - - - - - - - - - - - - - - - -
- - -
- - - - -
- - -
- - - - - -
- - Live flow of {new Date(displayList?.at(0)?.date ?? null)?.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', daySuffix: '2-digit' })} (NYSE Time) - -
- - -
- - -
-
-
- - {#if notFound === true} - - No Results Found - - {/if} -
- - -
- -
- - -
-
- - -
- - - - - - {#if isLoaded } - - -
- -
-
- - -
-
- Most Traded Symbol - - - {mostFrequentTicker?.ticker} - - {new Intl.NumberFormat("en", { - minimumFractionDigits: 0, - maximumFractionDigits: 0 - }).format(mostFrequentTicker?.count)} - -
-
- - - - -
-
- Highest Volume - - - {highestVolumeTicker?.ticker} - - {new Intl.NumberFormat("en", { - minimumFractionDigits: 0, - maximumFractionDigits: 0 - }).format(highestVolumeTicker?.volume)} - -
-
- - - -
-
- Highest Size - - - {highestSizeTicker?.ticker} - - {new Intl.NumberFormat("en", { - minimumFractionDigits: 0, - maximumFractionDigits: 0 - }).format(highestSizeTicker?.size)} - -
-
- - - -
-
- Highest Amount - - - {highestAmountTicker?.ticker} - - {abbreviateNumber(highestAmountTicker?.amount, true)} - -
-
- - - -
-
- Total Amount - - - {sumAmountTicker?.ticker} - - {abbreviateNumber(sumAmountTicker?.totalAmount, true)} - -
-
- - - -
-
- -
- - - - - - - -
- - -
- - - - - - - - - - - - - {#each displayList as item,index} - - - - - - - - - - - - - - - - - - - - {/each} - -
TimeCompanySizeVolumePriceAmount
- {formatTime(item?.date)} - goto(`/stocks/${item?.symbol}`)} class="text-sm text-start whitespace-nowrap"> -
- {item?.symbol} - - {item?.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} - -
-
- {new Intl.NumberFormat("en", { - minimumFractionDigits: 0, - maximumFractionDigits: 0 - }).format(item?.size)} - - {new Intl.NumberFormat("en", { - minimumFractionDigits: 0, - maximumFractionDigits: 0 - }).format(item?.volume)} - - ${item?.price} - - {abbreviateNumber(item?.price*item?.volume,true)} -
- - - -
- -
- - -
- -
- - - {:else} -
-
- -
-
- - {/if} -
- -
- - - \ No newline at end of file diff --git a/src/routes/dark-pool-flow/+page.ts b/src/routes/dark-pool-flow/+page.ts deleted file mode 100644 index 625a5057..00000000 --- a/src/routes/dark-pool-flow/+page.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { getCache, setCache, isOpen } from "$lib/store"; - -const checkMarketHour = async () => { - const holidays = [ - "2024-01-01", - "2024-01-15", - "2024-02-19", - "2024-03-29", - "2024-05-27", - "2024-06-19", - "2024-07-04", - "2024-09-02", - "2024-11-28", - "2024-12-25", - ]; - const currentDate = new Date().toISOString().split("T")[0]; - - // Get the current time in the ET time zone - const etTimeZone = "America/New_York"; - const currentTime = new Date().toLocaleString("en-US", { - timeZone: etTimeZone, - }); - - // Determine if the NYSE is currently open or closed - const currentHour = new Date(currentTime).getHours(); - const isWeekendValue = - new Date(currentTime).getDay() === 6 || - new Date(currentTime).getDay() === 0; - const isBeforeMarketOpenValue = - currentHour < 9 || - (currentHour === 9 && new Date(currentTime).getMinutes() < 30); - const isAfterMarketCloseValue = currentHour >= 16; - - isOpen.set( - !( - isWeekendValue || - isBeforeMarketOpenValue || - isAfterMarketCloseValue || - holidays?.includes(currentDate) - ), - ); -}; - -export const load = async ({ parent }) => { - checkMarketHour(); - const { apiKey, apiURL, user } = await parent(); - - const getDarkPoolFlow = async () => { - let output; - - const cachedData = getCache("", "getDarkPoolFlow"); - if (cachedData) { - output = cachedData; - } else { - const response = await fetch(apiURL + "/dark-pool-flow", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getDarkPoolFlow"); - } - - output = user?.tier !== "Pro" ? output?.slice(0, 6) : output; - - return output; - }; - - // Make sure to return a promise - return { - getDarkPoolFlow: await getDarkPoolFlow(), - }; -}; diff --git a/src/routes/etf/[tickerID]/+layout.svelte b/src/routes/etf/[tickerID]/+layout.svelte index d1e579c3..2b10f168 100644 --- a/src/routes/etf/[tickerID]/+layout.svelte +++ b/src/routes/etf/[tickerID]/+layout.svelte @@ -166,9 +166,10 @@ async function toggleUserWatchlist(watchListId: string) { 'userId': data?.user?.id, 'watchListId': watchListId, 'ticker': $etfTicker, + 'path': 'update-watchlist' }; - const response = await fetch(data?.fastifyURL + '/update-watchlist', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -198,22 +199,7 @@ async function toggleUserWatchlist(watchListId: string) { } } -async function fetchPortfolio() -{ - const postData = {'userId': data?.user?.id}; - const response = await fetch(data?.fastifyURL+'/get-portfolio-data', { - method: 'POST', - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify(postData) - }); - - userPortfolio = (await response.json())?.items; - -} - @@ -291,10 +277,7 @@ async function fetchPortfolio() let LoginPopup; - let BuyTrade; - let SellTrade; let PriceAlert; - let AddPortfolio; onMount(async () => { @@ -406,34 +389,9 @@ async function fetchPortfolio() } } -$: { - if(userPortfolio) { - availableCash = userPortfolio?.at(0)?.availableCash; - const userHoldingList = userPortfolio?.at(0)?.holdings || []; - const stockIndex = userHoldingList?.findIndex(stock => stock?.symbol === $etfTicker); - if (stockIndex !== -1) - { - - holdingShares = userHoldingList[stockIndex]['numberOfShares']; - } - else { - holdingShares = 0; - } - } -} - $: { - if(typeof window !== 'undefined' && $traded && data?.user && $etfTicker?.length !== 0) - { - fetchPortfolio(); - $traded = false; - } - } - - - let charNumber = 50; diff --git a/src/routes/fda-calendar/+page.server.ts b/src/routes/fda-calendar/+page.server.ts new file mode 100644 index 00000000..38c55bcd --- /dev/null +++ b/src/routes/fda-calendar/+page.server.ts @@ -0,0 +1,22 @@ +export const load = async ({ locals }) => { + const getFDACalendar = async () => { + const { apiURL, apiKey } = locals; + + const response = await fetch(apiURL + "/fda-calendar", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getFDACalendar: await getFDACalendar(), + }; +}; diff --git a/src/routes/fda-calendar/+page.ts b/src/routes/fda-calendar/+page.ts deleted file mode 100644 index f9efa8fc..00000000 --- a/src/routes/fda-calendar/+page.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getFDACalendar = async () => { - let output; - - const cachedData = getCache("", "getFDACalendar"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const response = await fetch(apiURL + "/fda-calendar", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getFDACalendar"); - } - - return output; - }; - - // Make sure to return a promise - return { - getFDACalendar: await getFDACalendar(), - }; -}; diff --git a/src/routes/heatmaps/+page.server.ts b/src/routes/heatmaps/+page.server.ts new file mode 100644 index 00000000..9562bd2e --- /dev/null +++ b/src/routes/heatmaps/+page.server.ts @@ -0,0 +1,64 @@ +import { getCache, setCache } from "$lib/store"; + +export const load = async ({ locals }) => { + const { apiURL, apiKey } = locals; + + const getSP500HeatMap = async () => { + const postData = { index: "sp500" }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/heatmaps", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getDowJonesHeatMap = async () => { + const postData = { index: "dowjones" }; + // make the POST request to the endpoint + const response = await fetch(apiURL + "/heatmaps", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getNasdaqHeatMap = async () => { + const postData = { index: "nasdaq" }; + // make the POST request to the endpoint + const response = await fetch(apiURL + "/heatmaps", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getSP500HeatMap: await getSP500HeatMap(), + getDowJonesHeatMap: await getDowJonesHeatMap(), + getNasdaqHeatMap: await getNasdaqHeatMap(), + }; +}; diff --git a/src/routes/heatmaps/+page.ts b/src/routes/heatmaps/+page.ts deleted file mode 100644 index bb64f3c9..00000000 --- a/src/routes/heatmaps/+page.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const { apiURL, apiKey } = await parent(); - - const getSP500HeatMap = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getSP500HeatMap"); - if (cachedData) { - output = cachedData; - } else { - const postData = { index: "sp500" }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/heatmaps", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getSP500HeatMap' - setCache("", output, "getSP500HeatMap"); - } - - return output; - }; - - const getDowJonesHeatMap = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getDowJonesHeatMap"); - if (cachedData) { - output = cachedData; - } else { - const postData = { index: "dowjones" }; - // make the POST request to the endpoint - const response = await fetch(apiURL + "/heatmaps", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getDowJonesHeatMap' - setCache("", output, "getDowJonesHeatMap"); - } - - return output; - }; - - const getNasdaqHeatMap = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getNasdaqHeatMap"); - if (cachedData) { - output = cachedData; - } else { - const postData = { index: "nasdaq" }; - // make the POST request to the endpoint - const response = await fetch(apiURL + "/heatmaps", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getNasdaqHeatMap' - setCache("", output, "getNasdaqHeatMap"); - } - - return output; - }; - - // Make sure to return a promise - return { - getSP500HeatMap: await getSP500HeatMap(), - getDowJonesHeatMap: await getDowJonesHeatMap(), - getNasdaqHeatMap: await getNasdaqHeatMap(), - }; -}; diff --git a/src/routes/leaderboard/+page.svelte b/src/routes/leaderboard/+page.svelte deleted file mode 100644 index db306d7f..00000000 --- a/src/routes/leaderboard/+page.svelte +++ /dev/null @@ -1,511 +0,0 @@ - - - - - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} Leaderboard Stocks Β· stocknear - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
-
-

- Leaderboard -

-

- {displayMonth} 2024 πŸš€ -

-
- -
- - Tournament ends in - - -
-
- - - - days -
-
- - - - hours -
-
- - - - min -
-
- - - - sec -
-
-
- -
- - - - - - -
-
- - -
-
- View all Leaderboard's -
-
- -
-
- - - {#if leaderboard?.length > 3 && isLoaded} -

- Top 3 Investors -

-
- - - - - - - - - - - -
- - {/if} - - {#if isLoaded} - - {#if leaderboard?.length ===0} -

- No Participation in the Tournament yet. Be the first and start the game πŸ”₯ -

- - - Get Started - - - - - - {:else} - {#each (leaderboard?.length >=3 ? leaderboard?.slice(3,-1) : leaderboard) as item,index } -
-
- -
- - {item?.rank} - - -
- User avatar -
- -
- -
-
- - {item?.expand?.user?.username > 7 ? item?.expand?.user?.username?.slice(0,7) + "..." : item?.expand?.user?.username} - - -
- ${new Intl.NumberFormat("en", { - minimumFractionDigits: 2, - maximumFractionDigits: 2 - }).format(item?.accountValue)} - -
- - {#if item?.overallReturn > 0} - - - - +{item?.overallReturn?.toFixed(2)}% - - {:else if item?.overallReturn < 0} - - - {item?.overallReturn?.toFixed(2)}% - - {:else} - - - {item?.overallReturn?.toFixed(2)}% - - {/if} - -
- -
- -
- -
- -
-
- {/each} - - - - - - - - - - - - - - {#each (leaderboard?.length >=3 ? leaderboard?.slice(3,-1) : leaderboard) as item,index} - - - - - - - - - - - - - {/each} - - - - {/if} - - - - - {:else} -
-
- -
-
- {/if} - - - -
- - diff --git a/src/routes/leaderboard/+page.ts b/src/routes/leaderboard/+page.ts deleted file mode 100644 index b7d0c832..00000000 --- a/src/routes/leaderboard/+page.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ params, parent }) => { - const getLeaderboard = async () => { - const currentDate = new Date(); - const year = currentDate.getFullYear(); - const currentMonthIndex = currentDate.getMonth(); - const nextMonthIndex = (currentMonthIndex + 1) % 12; - const nextYear = year + Math.floor((currentMonthIndex + 1) / 12); - const nextMonth = String(nextMonthIndex + 1).padStart(2, "0"); - const startDate = `${year}-${String(currentMonthIndex + 1).padStart(2, "0")}-01`; - const endDate = `${nextYear}-${nextMonth}-01`; - - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getLeaderboard"); - if (cachedData) { - output = cachedData; - } else { - const { fastifyURL } = await parent(); - - const postData = { - startDate: startDate, - endDate: endDate, - }; - - const response = await fetch(fastifyURL + "/leaderboard", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(postData), - }); - - output = (await response.json())?.items - ?.filter((item) => item.rank !== 0) - ?.sort((a, b) => a.rank - b.rank); - - // Cache the data for this specific tickerID with a specific name 'getLeaderboard' - setCache("", output, "getLeaderboard"); - } - - return output; - }; - - // Make sure to return a promise - return { - getLeaderboard: await getLeaderboard(), - }; -}; diff --git a/src/routes/list/amex-stocks/+page.server.ts b/src/routes/list/amex-stocks/+page.server.ts new file mode 100644 index 00000000..204ffa83 --- /dev/null +++ b/src/routes/list/amex-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getAmexStocks = async () => { + const { apiURL, apiKey } = locals; + const postData = { filterList: "amex" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getAmexStocks: await getAmexStocks(), + }; +}; diff --git a/src/routes/list/amex-stocks/+page.ts b/src/routes/list/amex-stocks/+page.ts deleted file mode 100644 index 0b09015d..00000000 --- a/src/routes/list/amex-stocks/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getAmexStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getAmexStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - const postData = { filterList: "amex" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getAmexStocks' - setCache("", output, "getAmexStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getAmexStocks: await getAmexStocks(), - }; -}; diff --git a/src/routes/list/bitcoin-etfs/+page.server.ts b/src/routes/list/bitcoin-etfs/+page.server.ts new file mode 100644 index 00000000..a5de381e --- /dev/null +++ b/src/routes/list/bitcoin-etfs/+page.server.ts @@ -0,0 +1,22 @@ +export const load = async ({ locals }) => { + const getETFBitcoinList = async () => { + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/etf-bitcoin-list", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getETFBitcoinList: await getETFBitcoinList(), + }; +}; diff --git a/src/routes/list/bitcoin-etfs/+page.ts b/src/routes/list/bitcoin-etfs/+page.ts deleted file mode 100644 index 22e96851..00000000 --- a/src/routes/list/bitcoin-etfs/+page.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getETFBitcoinList = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getETFBitcoinList"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const response = await fetch(apiURL + "/etf-bitcoin-list", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getETFBitcoinList' - setCache("", output, "getETFBitcoinList"); - } - - return output; - }; - - // Make sure to return a promise - return { - getETFBitcoinList: await getETFBitcoinList(), - }; -}; diff --git a/src/routes/list/canadian-stocks-us/+page.server.ts b/src/routes/list/canadian-stocks-us/+page.server.ts new file mode 100644 index 00000000..7a296dbb --- /dev/null +++ b/src/routes/list/canadian-stocks-us/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getCanadianStocksUS = async () => { + const { apiURL, apiKey } = locals; + + const postData = { filterList: "CA" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getCanadianStocksUS: await getCanadianStocksUS(), + }; +}; diff --git a/src/routes/list/canadian-stocks-us/+page.ts b/src/routes/list/canadian-stocks-us/+page.ts deleted file mode 100644 index bdbb1818..00000000 --- a/src/routes/list/canadian-stocks-us/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getCanadianStocksUS = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getCanadianStocksUS"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { filterList: "CA" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getCanadianStocksUS' - setCache("", output, "getCanadianStocksUS"); - } - - return output; - }; - - // Make sure to return a promise - return { - getCanadianStocksUS: await getCanadianStocksUS(), - }; -}; diff --git a/src/routes/list/chinese-stocks-us/+page.server.ts b/src/routes/list/chinese-stocks-us/+page.server.ts new file mode 100644 index 00000000..ea1e8d1e --- /dev/null +++ b/src/routes/list/chinese-stocks-us/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getChineseStocksUS = async () => { + const { apiURL, apiKey } = locals; + + const postData = { filterList: "CN" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getChineseStocksUS: await getChineseStocksUS(), + }; +}; diff --git a/src/routes/list/chinese-stocks-us/+page.ts b/src/routes/list/chinese-stocks-us/+page.ts deleted file mode 100644 index 350c2138..00000000 --- a/src/routes/list/chinese-stocks-us/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getChineseStocksUS = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getChineseStocksUS"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { filterList: "CN" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getChineseStocksUS' - setCache("", output, "getChineseStocksUS"); - } - - return output; - }; - - // Make sure to return a promise - return { - getChineseStocksUS: await getChineseStocksUS(), - }; -}; diff --git a/src/routes/list/delisted-stocks/+page.server.ts b/src/routes/list/delisted-stocks/+page.server.ts new file mode 100644 index 00000000..607b1636 --- /dev/null +++ b/src/routes/list/delisted-stocks/+page.server.ts @@ -0,0 +1,22 @@ +export const load = async ({ locals }) => { + const getDelistedStocks = async () => { + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/delisted-companies", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getDelistedStocks: await getDelistedStocks(), + }; +}; diff --git a/src/routes/list/delisted-stocks/+page.ts b/src/routes/list/delisted-stocks/+page.ts deleted file mode 100644 index 24b7c793..00000000 --- a/src/routes/list/delisted-stocks/+page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getDelistedStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getDelistedStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const response = await fetch(apiURL + "/delisted-companies", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - setCache("", output, "getDelistedStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getDelistedStocks: await getDelistedStocks(), - }; -}; diff --git a/src/routes/list/dividend-aristocrats/+page.server.ts b/src/routes/list/dividend-aristocrats/+page.server.ts new file mode 100644 index 00000000..56d4aa45 --- /dev/null +++ b/src/routes/list/dividend-aristocrats/+page.server.ts @@ -0,0 +1,22 @@ +export const load = async ({ locals }) => { + const getDividendAristocrats = async () => { + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/dividend-aristocrats", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getDividendAristocrats: await getDividendAristocrats(), + }; +}; diff --git a/src/routes/list/dividend-aristocrats/+page.ts b/src/routes/list/dividend-aristocrats/+page.ts deleted file mode 100644 index 0adbab38..00000000 --- a/src/routes/list/dividend-aristocrats/+page.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getDividendAristocrats = async () => { - // Get cached data for the specific tickerID - const cachedData = getCache("", "getDividendAristocrats"); - if (cachedData) { - return cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const response = await fetch(apiURL + "/dividend-aristocrats", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - const output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getDividendAristocrats' - setCache("", output, "getDividendAristocrats"); - - return output; - } - }; - - // Make sure to return a promise - return { - getDividendAristocrats: await getDividendAristocrats(), - }; -}; diff --git a/src/routes/list/dividend-kings/+page.server.ts b/src/routes/list/dividend-kings/+page.server.ts new file mode 100644 index 00000000..352a35ff --- /dev/null +++ b/src/routes/list/dividend-kings/+page.server.ts @@ -0,0 +1,22 @@ +export const load = async ({ locals }) => { + const getDividendKings = async () => { + const { apiKey, apiURL } = locals; + + const response = await fetch(apiURL + "/dividend-kings", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getDividendKings: await getDividendKings(), + }; +}; diff --git a/src/routes/list/dividend-kings/+page.ts b/src/routes/list/dividend-kings/+page.ts deleted file mode 100644 index 5130954d..00000000 --- a/src/routes/list/dividend-kings/+page.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getDividendKings = async () => { - // Get cached data for the specific tickerID - const cachedData = getCache("", "getDividendKings"); - if (cachedData) { - return cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const response = await fetch(apiURL + "/dividend-kings", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - const output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getDividendKings' - setCache("", output, "getDividendKings"); - - return output; - } - }; - - // Make sure to return a promise - return { - getDividendKings: await getDividendKings(), - }; -}; diff --git a/src/routes/list/dow-jones-stocks/+page.server.ts b/src/routes/list/dow-jones-stocks/+page.server.ts new file mode 100644 index 00000000..ddaad3ab --- /dev/null +++ b/src/routes/list/dow-jones-stocks/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getDowJonesConstituentStocks = async () => { + const { apiKey, apiURL } = locals; + + const postData = { filterList: "dowjonesConstituent" }; + + const response = await fetch(apiURL + "/exchange-constituents", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getDowJonesConstituentStocks: await getDowJonesConstituentStocks(), + }; +}; diff --git a/src/routes/list/dow-jones-stocks/+page.ts b/src/routes/list/dow-jones-stocks/+page.ts deleted file mode 100644 index 3fa7e2c7..00000000 --- a/src/routes/list/dow-jones-stocks/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getDowJonesConstituentStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getDowJonesConstituentStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "dowjonesConstituent" }; - - const response = await fetch(apiURL + "/exchange-constituents", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache("", output, "getDowJonesConstituentStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getDowJonesConstituentStocks: await getDowJonesConstituentStocks(), - }; -}; diff --git a/src/routes/list/german-stocks-us/+page.server.ts b/src/routes/list/german-stocks-us/+page.server.ts new file mode 100644 index 00000000..d4599611 --- /dev/null +++ b/src/routes/list/german-stocks-us/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getGermanStocksUS = async () => { + const { apiURL, apiKey } = locals; + + const postData = { filterList: "DE" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getGermanStocksUS: await getGermanStocksUS(), + }; +}; diff --git a/src/routes/list/german-stocks-us/+page.ts b/src/routes/list/german-stocks-us/+page.ts deleted file mode 100644 index 0b63a000..00000000 --- a/src/routes/list/german-stocks-us/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getGermanStocksUS = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getGermanStocksUS"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { filterList: "DE" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getGermanStocksUS' - setCache("", output, "getGermanStocksUS"); - } - - return output; - }; - - // Make sure to return a promise - return { - getGermanStocksUS: await getGermanStocksUS(), - }; -}; diff --git a/src/routes/list/indian-stocks-us/+page.server.ts b/src/routes/list/indian-stocks-us/+page.server.ts new file mode 100644 index 00000000..64614574 --- /dev/null +++ b/src/routes/list/indian-stocks-us/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getIndianStocksUS = async () => { + const { apiURL, apiKey } = locals; + + const postData = { filterList: "IN" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getIndianStocksUS: await getIndianStocksUS(), + }; +}; diff --git a/src/routes/list/indian-stocks-us/+page.ts b/src/routes/list/indian-stocks-us/+page.ts deleted file mode 100644 index e3c17803..00000000 --- a/src/routes/list/indian-stocks-us/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getIndianStocksUS = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getIndianStocksUS"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { filterList: "IN" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getIndianStocksUS' - setCache("", output, "getIndianStocksUS"); - } - - return output; - }; - - // Make sure to return a promise - return { - getIndianStocksUS: await getIndianStocksUS(), - }; -}; diff --git a/src/routes/list/israeli-stocks-us/+page.server.ts b/src/routes/list/israeli-stocks-us/+page.server.ts new file mode 100644 index 00000000..522cad21 --- /dev/null +++ b/src/routes/list/israeli-stocks-us/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getIsraeliStocksUS = async () => { + const { apiURL, apiKey } = locals; + + const postData = { filterList: "IL" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getIsraeliStocksUS: await getIsraeliStocksUS(), + }; +}; diff --git a/src/routes/list/israeli-stocks-us/+page.ts b/src/routes/list/israeli-stocks-us/+page.ts deleted file mode 100644 index 9bff5096..00000000 --- a/src/routes/list/israeli-stocks-us/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getIsraeliStocksUS = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getIsraeliStocksUS"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { filterList: "IL" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getIsraeliStocksUS' - setCache("", output, "getIsraeliStocksUS"); - } - - return output; - }; - - // Make sure to return a promise - return { - getIsraeliStocksUS: await getIsraeliStocksUS(), - }; -}; diff --git a/src/routes/list/japanese-stocks-us/+page.server.ts b/src/routes/list/japanese-stocks-us/+page.server.ts new file mode 100644 index 00000000..e2ba9ac4 --- /dev/null +++ b/src/routes/list/japanese-stocks-us/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getJapaneseStocksUS = async () => { + const { apiURL, apiKey } = locals; + + const postData = { filterList: "JP" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getJapaneseStocksUS: await getJapaneseStocksUS(), + }; +}; diff --git a/src/routes/list/japanese-stocks-us/+page.ts b/src/routes/list/japanese-stocks-us/+page.ts deleted file mode 100644 index f5b935c5..00000000 --- a/src/routes/list/japanese-stocks-us/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getJapaneseStocksUS = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getJapaneseStocksUS"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { filterList: "JP" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getJapaneseStocksUS' - setCache("", output, "getJapaneseStocksUS"); - } - - return output; - }; - - // Make sure to return a promise - return { - getJapaneseStocksUS: await getJapaneseStocksUS(), - }; -}; diff --git a/src/routes/list/large-cap-stocks/+page.server.ts b/src/routes/list/large-cap-stocks/+page.server.ts new file mode 100644 index 00000000..d3110516 --- /dev/null +++ b/src/routes/list/large-cap-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getLargeCapStocks = async () => { + const { apiKey, apiURL } = locals; + const postData = { filterList: "largeCap" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getLargeCapStocks: await getLargeCapStocks(), + }; +}; diff --git a/src/routes/list/large-cap-stocks/+page.ts b/src/routes/list/large-cap-stocks/+page.ts deleted file mode 100644 index 76883cf7..00000000 --- a/src/routes/list/large-cap-stocks/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getLargeCapStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getLargeCapStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { filterList: "largeCap" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getLargeCapStocks' - setCache("", output, "getLargeCapStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getLargeCapStocks: await getLargeCapStocks(), - }; -}; diff --git a/src/routes/list/magnificent-seven/+page.server.ts b/src/routes/list/magnificent-seven/+page.server.ts new file mode 100644 index 00000000..6657883a --- /dev/null +++ b/src/routes/list/magnificent-seven/+page.server.ts @@ -0,0 +1,22 @@ +export const load = async ({ locals }) => { + const getMagnificentSeven = async () => { + const { apiURL, apiKey } = locals; + + const response = await fetch(apiURL + "/magnificent-seven", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getMagnificentSeven: await getMagnificentSeven(), + }; +}; diff --git a/src/routes/list/magnificent-seven/+page.ts b/src/routes/list/magnificent-seven/+page.ts deleted file mode 100644 index 27e8e30b..00000000 --- a/src/routes/list/magnificent-seven/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getMagnificentSeven = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getMagnificentSeven"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const response = await fetch(apiURL + "/magnificent-seven", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = await response.json(); - - console.log(output); - - // Cache the data for this specific tickerID with a specific name 'getMagnificentSeven' - setCache("", output, "getMagnificentSeven"); - } - - return output; - }; - - // Make sure to return a promise - return { - getMagnificentSeven: await getMagnificentSeven(), - }; -}; diff --git a/src/routes/list/mega-cap-stocks/+page.server.ts b/src/routes/list/mega-cap-stocks/+page.server.ts new file mode 100644 index 00000000..17810e5f --- /dev/null +++ b/src/routes/list/mega-cap-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getMegaCapStocks = async () => { + const { apiKey, apiURL } = locals; + const postData = { filterList: "megaCap" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getMegaCapStocks: await getMegaCapStocks(), + }; +}; diff --git a/src/routes/list/mega-cap-stocks/+page.ts b/src/routes/list/mega-cap-stocks/+page.ts deleted file mode 100644 index 8e2584fb..00000000 --- a/src/routes/list/mega-cap-stocks/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getMegaCapStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getMegaCapStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { filterList: "megaCap" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getMegaCapStocks' - setCache("", output, "getMegaCapStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getMegaCapStocks: await getMegaCapStocks(), - }; -}; diff --git a/src/routes/list/micro-cap-stocks/+page.server.ts b/src/routes/list/micro-cap-stocks/+page.server.ts new file mode 100644 index 00000000..079ded1f --- /dev/null +++ b/src/routes/list/micro-cap-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getMicroCapStocks = async () => { + const { apiKey, apiURL } = locals; + const postData = { filterList: "microCap" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getMicroCapStocks: await getMicroCapStocks(), + }; +}; diff --git a/src/routes/list/micro-cap-stocks/+page.ts b/src/routes/list/micro-cap-stocks/+page.ts deleted file mode 100644 index 03bf17e6..00000000 --- a/src/routes/list/micro-cap-stocks/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getMicroCapStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getMicroCapStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { filterList: "microCap" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getMicroCapStocks' - setCache("", output, "getMicroCapStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getMicroCapStocks: await getMicroCapStocks(), - }; -}; diff --git a/src/routes/list/mid-cap-stocks/+page.server.ts b/src/routes/list/mid-cap-stocks/+page.server.ts new file mode 100644 index 00000000..9d39609f --- /dev/null +++ b/src/routes/list/mid-cap-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getMidCapStocks = async () => { + const { apiKey, apiURL } = locals; + const postData = { filterList: "midCap" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getMidCapStocks: await getMidCapStocks(), + }; +}; diff --git a/src/routes/list/mid-cap-stocks/+page.ts b/src/routes/list/mid-cap-stocks/+page.ts deleted file mode 100644 index 6e7293ba..00000000 --- a/src/routes/list/mid-cap-stocks/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getMidCapStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getMidCapStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { filterList: "midCap" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getMidCapStocks' - setCache("", output, "getMidCapStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getMidCapStocks: await getMidCapStocks(), - }; -}; diff --git a/src/routes/list/nano-cap-stocks/+page.server.ts b/src/routes/list/nano-cap-stocks/+page.server.ts new file mode 100644 index 00000000..4636a595 --- /dev/null +++ b/src/routes/list/nano-cap-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getNanoCapStocks = async () => { + const { apiKey, apiURL } = locals; + const postData = { filterList: "nanoCap" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getNanoCapStocks: await getNanoCapStocks(), + }; +}; diff --git a/src/routes/list/nano-cap-stocks/+page.ts b/src/routes/list/nano-cap-stocks/+page.ts deleted file mode 100644 index 23fcaa6f..00000000 --- a/src/routes/list/nano-cap-stocks/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getNanoCapStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getNanoCapStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - const postData = { filterList: "nanoCap" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getNanoCapStocks' - setCache("", output, "getNanoCapStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getNanoCapStocks: await getNanoCapStocks(), - }; -}; diff --git a/src/routes/list/nasdaq-100-stocks/+page.server.ts b/src/routes/list/nasdaq-100-stocks/+page.server.ts new file mode 100644 index 00000000..3a0a633a --- /dev/null +++ b/src/routes/list/nasdaq-100-stocks/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getNasdaqConstituentsStocks = async () => { + const { apiKey, apiURL } = locals; + + const postData = { filterList: "nasdaqConstituent" }; + + const response = await fetch(apiURL + "/exchange-constituents", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getNasdaqConstituentsStocks: await getNasdaqConstituentsStocks(), + }; +}; diff --git a/src/routes/list/nasdaq-100-stocks/+page.ts b/src/routes/list/nasdaq-100-stocks/+page.ts deleted file mode 100644 index 475ca359..00000000 --- a/src/routes/list/nasdaq-100-stocks/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getNasdaqConstituentsStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getNasdaqConstituentsStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { filterList: "nasdaqConstituent" }; - - const response = await fetch(apiURL + "/exchange-constituents", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache("", output, "getNasdaqConstituentsStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getNasdaqConstituentsStocks: await getNasdaqConstituentsStocks(), - }; -}; diff --git a/src/routes/list/nasdaq-stocks/+page.server.ts b/src/routes/list/nasdaq-stocks/+page.server.ts new file mode 100644 index 00000000..6ca6aca4 --- /dev/null +++ b/src/routes/list/nasdaq-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getNasdaqStocks = async () => { + const { apiURL, apiKey } = locals; + const postData = { filterList: "nasdaq" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getNasdaqStocks: await getNasdaqStocks(), + }; +}; diff --git a/src/routes/list/nasdaq-stocks/+page.ts b/src/routes/list/nasdaq-stocks/+page.ts deleted file mode 100644 index 17e05de3..00000000 --- a/src/routes/list/nasdaq-stocks/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getNasdaqStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getNasdaqStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "nasdaq" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getNasdaqStocks' - setCache("", output, "getNasdaqStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getNasdaqStocks: await getNasdaqStocks(), - }; -}; diff --git a/src/routes/list/nyse-stocks/+page.server.ts b/src/routes/list/nyse-stocks/+page.server.ts new file mode 100644 index 00000000..9a69d3df --- /dev/null +++ b/src/routes/list/nyse-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getNyseStocks = async () => { + const { apiURL, apiKey } = locals; + const postData = { filterList: "nyse" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getNyseStocks: await getNyseStocks(), + }; +}; diff --git a/src/routes/list/nyse-stocks/+page.ts b/src/routes/list/nyse-stocks/+page.ts deleted file mode 100644 index 67874998..00000000 --- a/src/routes/list/nyse-stocks/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getNyseStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getNyseStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { filterList: "nyse" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getNyseStocks' - setCache("", output, "getNyseStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getNyseStocks: await getNyseStocks(), - }; -}; diff --git a/src/routes/list/reit-stocks/+page.server.ts b/src/routes/list/reit-stocks/+page.server.ts new file mode 100644 index 00000000..57ffa7cd --- /dev/null +++ b/src/routes/list/reit-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getAllREITs = async () => { + const { apiKey, apiURL } = locals; + + const postData = { filterList: "reit" }; + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getAllREITs: await getAllREITs(), + }; +}; diff --git a/src/routes/list/reit-stocks/+page.ts b/src/routes/list/reit-stocks/+page.ts deleted file mode 100644 index a8930b06..00000000 --- a/src/routes/list/reit-stocks/+page.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getAllREITs = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getAllREITs"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "reit" }; - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache("", output, "getAllREITs"); - } - - return output; - }; - - // Make sure to return a promise - return { - getAllREITs: await getAllREITs(), - }; -}; diff --git a/src/routes/list/small-cap-stocks/+page.server.ts b/src/routes/list/small-cap-stocks/+page.server.ts new file mode 100644 index 00000000..f421ca2f --- /dev/null +++ b/src/routes/list/small-cap-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getSmallCapStocks = async () => { + const { apiKey, apiURL } = locals; + const postData = { filterList: "smallCap" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getSmallCapStocks: await getSmallCapStocks(), + }; +}; diff --git a/src/routes/list/small-cap-stocks/+page.ts b/src/routes/list/small-cap-stocks/+page.ts deleted file mode 100644 index 36f8d2ba..00000000 --- a/src/routes/list/small-cap-stocks/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getSmallCapStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getSmallCapStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { filterList: "smallCap" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getSmallCapStocks' - setCache("", output, "getSmallCapStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getSmallCapStocks: await getSmallCapStocks(), - }; -}; diff --git a/src/routes/list/sp-500-stocks/+page.server.ts b/src/routes/list/sp-500-stocks/+page.server.ts new file mode 100644 index 00000000..ca3d8a86 --- /dev/null +++ b/src/routes/list/sp-500-stocks/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getSPConstituentsStocks = async () => { + const { apiKey, apiURL } = locals; + + const postData = { filterList: "sp500Constituent" }; + + const response = await fetch(apiURL + "/exchange-constituents", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getSPConstituentsStocks: await getSPConstituentsStocks(), + }; +}; diff --git a/src/routes/list/sp-500-stocks/+page.ts b/src/routes/list/sp-500-stocks/+page.ts deleted file mode 100644 index dc2e74e1..00000000 --- a/src/routes/list/sp-500-stocks/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getSPConstituentsStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getSPConstituentsStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { filterList: "sp500Constituent" }; - - const response = await fetch(apiURL + "/exchange-constituents", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache("", output, "getSPConstituentsStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getSPConstituentsStocks: await getSPConstituentsStocks(), - }; -}; diff --git a/src/routes/list/uk-stocks-us/+page.server.ts b/src/routes/list/uk-stocks-us/+page.server.ts new file mode 100644 index 00000000..34cc2113 --- /dev/null +++ b/src/routes/list/uk-stocks-us/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals }) => { + const getUKStocksUS = async () => { + const { apiURL, apiKey } = locals; + + const postData = { filterList: "GB" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getUKStocksUS: await getUKStocksUS(), + }; +}; diff --git a/src/routes/list/uk-stocks-us/+page.ts b/src/routes/list/uk-stocks-us/+page.ts deleted file mode 100644 index 75896669..00000000 --- a/src/routes/list/uk-stocks-us/+page.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getUKStocksUS = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getUKStocksUS"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { filterList: "GB" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - setCache("", output, "getUKStocksUS"); - } - - return output; - }; - - // Make sure to return a promise - return { - getUKStocksUS: await getUKStocksUS(), - }; -}; diff --git a/src/routes/list/xetra-stocks/+page.server.ts b/src/routes/list/xetra-stocks/+page.server.ts new file mode 100644 index 00000000..58b1fd85 --- /dev/null +++ b/src/routes/list/xetra-stocks/+page.server.ts @@ -0,0 +1,24 @@ +export const load = async ({ locals }) => { + const getXetraStocks = async () => { + const { apiURL, apiKey } = locals; + const postData = { filterList: "xetra" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getXetraStocks: await getXetraStocks(), + }; +}; diff --git a/src/routes/list/xetra-stocks/+page.ts b/src/routes/list/xetra-stocks/+page.ts deleted file mode 100644 index b0334dfa..00000000 --- a/src/routes/list/xetra-stocks/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getXetraStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getXetraStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "xetra" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getXetraStocks' - setCache("", output, "getXetraStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getXetraStocks: await getXetraStocks(), - }; -}; diff --git a/src/routes/market-news/press-release/+page.svelte b/src/routes/market-news/press-release/+page.svelte deleted file mode 100644 index b2972f39..00000000 --- a/src/routes/market-news/press-release/+page.svelte +++ /dev/null @@ -1,130 +0,0 @@ - - - - - - - - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} Today's Crypto News and Breaking Stories Β· stocknear - - - - - - - - - - - - - - - - - - - - - -
- -
-
-
-
-
- {#if news.length !== 0} - {#each news as item} -
- - -
- news image -
-
- -
- - - - {item?.title?.length > 120 ? item?.title?.slice(0,120) +'...' : item?.title} - -

- {item?.text?.length > 100 ? item?.text?.slice(0,100) + "..." : item?.text} -

-
- -
- - {/each} - - - - - - {/if} -
- -
-
-
-
- - - - - - - - - - \ No newline at end of file diff --git a/src/routes/market-news/press-release/+page.ts b/src/routes/market-news/press-release/+page.ts deleted file mode 100644 index b25537d2..00000000 --- a/src/routes/market-news/press-release/+page.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getPressRelease = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getPressRelease"); - if (cachedData) { - output = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - const postData = { newsType: "press-releases" }; - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/market-news", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getPressRelease' - setCache("", output, "getPressRelease"); - } - - return output; - }; - - // Make sure to return a promise - return { - getPressRelease: await getPressRelease(), - }; -}; diff --git a/src/routes/notifications/+page.svelte b/src/routes/notifications/+page.svelte index bed1673f..6faace09 100644 --- a/src/routes/notifications/+page.svelte +++ b/src/routes/notifications/+page.svelte @@ -34,9 +34,9 @@ for(let i = 0; i < notificationList?.length; i++) if (notificationIdList.length !== 0) { - const postData = {'unreadList': notificationIdList}; + const postData = {'unreadList': notificationIdList, 'path': 'update-notifications'}; - await fetch(data?.fastifyURL+'/update-notifications', { + await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" diff --git a/src/routes/politicians/[slug]/+page.server.ts b/src/routes/politicians/[slug]/+page.server.ts new file mode 100644 index 00000000..fdedaf45 --- /dev/null +++ b/src/routes/politicians/[slug]/+page.server.ts @@ -0,0 +1,60 @@ +import { getPartyForPoliticians } from "$lib/utils"; + +let politicianDistrict; +let politicianCongress; +let politicianParty = "n/a"; +// Function to load images only when they are viewed + +export const load = async ({ locals, params }) => { + const getPolitician = async () => { + let res; + + const { apiURL, apiKey } = locals; + + const postData = { politicianId: params.slug }; + + const response = await fetch(apiURL + "/politician-stats", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + const history = output?.history; + // Cache the data for this specific tickerID with a specific name 'getPolitician' + + if (output && history?.length > 0) { + let firstItem = history?.at(0); + let representative = firstItem?.representative || ""; + + representative = representative + ?.replace("Jr", "") + ?.replace(/Dr./g, "") + ?.replace(/Dr_/g, ""); + + const fullName = representative + ?.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_") + ?.trim(); + firstItem.representative = fullName?.replace(/_/g, " "); + + const party = getPartyForPoliticians(firstItem?.representative); + firstItem.party = party; + + politicianParty = firstItem?.party; + politicianDistrict = firstItem?.district; + politicianCongress = firstItem?.congress; + } + + res = { output, politicianParty, politicianDistrict, politicianCongress }; + + return res; + }; + + // Make sure to return a promise + return { + getPolitician: await getPolitician(), + }; +}; diff --git a/src/routes/politicians/[slug]/+page.ts b/src/routes/politicians/[slug]/+page.ts deleted file mode 100644 index 78a93faf..00000000 --- a/src/routes/politicians/[slug]/+page.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { getCache, setCache } from "$lib/store"; -import defaultAvatar from "$lib/images/senator/default-avatar.png"; -import { getPartyForPoliticians } from "$lib/utils"; - -let politicianDistrict; -let politicianCongress; -let politicianParty = "n/a"; -// Function to load images only when they are viewed - -export const load = async ({ parent, params }) => { - const getPolitician = async () => { - let res; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.slug, "getPolitician"); - if (cachedData) { - res = cachedData; - } else { - const { apiURL, apiKey } = await parent(); - - const postData = { politicianId: params.slug }; - - const response = await fetch(apiURL + "/politician-stats", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - const output = await response.json(); - const history = output?.history; - // Cache the data for this specific tickerID with a specific name 'getPolitician' - - if (output && history?.length > 0) { - let firstItem = history?.at(0); - let representative = firstItem?.representative || ""; - - representative = representative - ?.replace("Jr", "") - ?.replace(/Dr./g, "") - ?.replace(/Dr_/g, ""); - - const fullName = representative - ?.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_") - ?.trim(); - firstItem.representative = fullName?.replace(/_/g, " "); - - const party = getPartyForPoliticians(firstItem?.representative); - firstItem.party = party; - - politicianParty = firstItem?.party; - politicianDistrict = firstItem?.district; - politicianCongress = firstItem?.congress; - } - - res = { output, politicianParty, politicianDistrict, politicianCongress }; - setCache(params.slug, res, "getPolitician"); - } - - return res; - }; - - // Make sure to return a promise - return { - getPolitician: await getPolitician(), - }; -}; diff --git a/src/routes/portfolio/+page.server.ts b/src/routes/portfolio/+page.server.ts deleted file mode 100644 index 6614cf1e..00000000 --- a/src/routes/portfolio/+page.server.ts +++ /dev/null @@ -1,134 +0,0 @@ -import { error, fail, redirect } from "@sveltejs/kit"; -import { validateData } from "$lib/utils"; -import { loginUserSchema, registerUserSchema } from "$lib/schemas"; - -export const actions = { - login: async ({ request, locals }) => { - const { formData, errors } = await validateData( - await request.formData(), - loginUserSchema, - ); - - if (errors) { - return fail(400, { - data: formData, - errors: errors.fieldErrors, - }); - } - - try { - await locals.pb - .collection("users") - .authWithPassword(formData.email, formData.password); - - /* - if (!locals.pb?.authStore?.model?.verified) { - locals.pb.authStore.clear(); - return { - notVerified: true, - }; - } - */ - } catch (err) { - console.log("Error: ", err); - error(err.status, err.message); - } - - redirect(302, "/"); - }, - - register: async ({ locals, request }) => { - const { formData, errors } = await validateData( - await request.formData(), - registerUserSchema, - ); - - if (errors) { - return fail(400, { - data: formData, - errors: errors.fieldErrors, - }); - } - - try { - let newUser = await locals.pb.collection("users").create(formData); - /* -await locals.pb?.collection('users').update( - newUser?.id, { - 'freeTrial' : true, - 'tier': 'Pro', //Give new users a free trial for the Pro Subscription - }); -*/ - await locals.pb.collection("users").requestVerification(formData.email); - } catch (err) { - console.log("Error: ", err); - error(err.status, err.message); - } - - try { - await locals.pb - .collection("users") - .authWithPassword(formData.email, formData.password); - } catch (err) { - console.log("Error: ", err); - error(err.status, err.message); - } - - redirect(303, "/"); - }, - - oauth2: async ({ url, locals, request, cookies }) => { - const authMethods = await locals?.pb - ?.collection("users") - ?.listAuthMethods(); - - const data = await request?.formData(); - const providerSelected = data?.get("provider"); - - if (!authMethods) { - return { - authProviderRedirect: "", - authProviderState: "", - }; - } - const redirectURL = `${url.origin}/oauth`; - - const targetItem = authMethods.authProviders?.findIndex( - (item) => item?.name === providerSelected, - ); - //console.log("==================") - //console.log(authMethods.authProviders) - //console.log('target item is: ', targetItem) - - const provider = authMethods.authProviders[targetItem]; - const authProviderRedirect = `${provider.authUrl}${redirectURL}`; - const state = provider.state; - const verifier = provider.codeVerifier; - - cookies.set("state", state, { - httpOnly: true, - sameSite: "lax", - secure: true, - path: "/", - maxAge: 60 * 60, - }); - - cookies.set("verifier", verifier, { - httpOnly: true, - sameSite: "lax", - secure: true, - path: "/", - maxAge: 60 * 60, - }); - - cookies.set("provider", providerSelected, { - httpOnly: true, - sameSite: "lax", - secure: true, - path: "/", - maxAge: 60 * 60, - }); - - redirect(302, authProviderRedirect); - }, -}; diff --git a/src/routes/portfolio/+page.svelte b/src/routes/portfolio/+page.svelte deleted file mode 100644 index 6435957f..00000000 --- a/src/routes/portfolio/+page.svelte +++ /dev/null @@ -1,878 +0,0 @@ - - - - - - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} Portfolio Β· stocknear - - - - - - - - - - - - - - - - - - - - - - -
- - - -
-
- - -
-
-

- Portfolio Tournament -

-

- {displayMonth} 2024 πŸš€ -

-
- - -
- - - - - - -
-
- - - {#if isLoaded} -
-
- - {#if portfolio.length === 0} - -
- - -
-
- Portfolio -
- - - - - -
- -
- -
-
- - Account Value - - -
- - - $100,000.00 - -
- - - -
-
- - Available Cash - - -
- - $100,000.00 - -
- - - -
-
- - Overall Return - - -
- - 0.00% - -
- -
- - -
- -
- - -
- - - {:else} - - -
- - - - -
- -
-
- - Account Value - - -
- - - ${new Intl.NumberFormat("en", { - minimumFractionDigits: 2, - maximumFractionDigits: 2 - }).format(portfolio?.at(0)?.accountValue)} - -
- - - -
-
- - Available Cash - - -
- - - ${new Intl.NumberFormat("en", { - minimumFractionDigits: 2, - maximumFractionDigits: 2 - }).format(portfolio?.at(0)?.availableCash)} - -
- - - -
-
- - Overall Return - - -
- {#if portfolio?.at(0)?.overallReturn > 0} - - +{portfolio?.at(0)?.overallReturn?.toFixed(2)}% - - {:else if portfolio?.at(0)?.overallReturn < 0} - - {portfolio?.at(0)?.overallReturn?.toFixed(2)}% - - {:else} - - {portfolio?.at(0)?.overallReturn?.toFixed(2)}% - - {/if} -
- - - - -
- - -
- {/if} - - - - {#if portfolio?.length !== 0} - - -
-
-
- Holdings -
- -
- {#if holdingsList?.length === 0} -
- No Holdings found -
- -
- - - - Click on the Search Icon to find your favorite stocks and begin growing your portfolio. - -
- - - {:else} - - - - {#each holdingsList as item, index} - goto(`/${item?.assetType === 'etf' ? 'etf' : 'stocks'}/${item?.symbol}`)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] {index % 2 === 0 ? 'bg-opacity-[0.25] bg-[#323239]' : 'bg-[#09090B]'} border-b-[#09090B] cursor-pointer"> - - - - - - {/each} - -
-
-
- {item?.symbol} - {item.name?.length > charNumber ? item?.name?.slice(0,charNumber) + "..." : item?.name} -
- - x{item?.numberOfShares} - - - ${new Intl.NumberFormat("en", { - minimumFractionDigits: 2, - maximumFractionDigits: 2 - }).format(item?.numberOfShares * item?.currentPrice)} - -
-
-
-
-
-
- ${item?.currentPrice?.toFixed(2)} -
- {#if displayChange === "Change in %"} - {#if item?.sinceBoughtChange >=0} - - +{item?.sinceBoughtChange?.toFixed(2)}% - {:else} - - {item?.sinceBoughtChange?.toFixed(2)}% - {/if} - {:else} - {#if item?.sinceBoughtChange >=0} - - +${(item?.numberOfShares * item?.currentPrice * item?.sinceBoughtChange/100 )?.toFixed(2)} - {:else} - - ${(item?.numberOfShares * item?.currentPrice * item?.sinceBoughtChange/100 )?.toFixed(2)} - {/if} - {/if} -
-
-
-
- - {/if} -
- -
-
showTradingHistory = !showTradingHistory} class="cursor-pointer flex flex-row items-center justify-between"> -
- Trading History -
- -
- -
- - -
- {#if tradingHistoryList?.length === 0} -
- {#if showTradingHistory} - - No Trading History found - - {/if} -
- {:else} - {#if showTradingHistory} -
- - - {#each tradingHistoryList as item, index} - - - {/each} - -
-
-
- {item?.symbol} - {item.name?.length > charNumber ? item?.name.slice(0,charNumber) + "..." : item?.name} -
- -
- {#if item?.type === 'buy'} - Bought {item?.numberOfShares} shares at {item?.price?.toLocaleString(undefined, { - style: 'currency', - currency: 'USD', - })} - {:else} - Sold {item?.numberOfShares} shares at {item?.price?.toLocaleString(undefined, { - style: 'currency', - currency: 'USD', - })} - {/if} -
- -
-
-
- {/if} - {/if} -
- - {/if} - - - - - {:else} -
-
- -
-
- - - {/if} - - -
- - - - -{#if LoginPopup} - -{/if} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/routes/price-alert/+page.svelte b/src/routes/price-alert/+page.svelte index 16cb2e41..71f92847 100644 --- a/src/routes/price-alert/+page.svelte +++ b/src/routes/price-alert/+page.svelte @@ -128,10 +128,11 @@ async function handleDelete() { priceAlertList = [...priceAlertList]; const postData = { - 'priceAlertIdList': deletePriceAlertList + 'priceAlertIdList': deletePriceAlertList, + 'path': 'delete-price-alert' } - const response = await fetch(data?.fastifyURL+'/delete-price-alert', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" diff --git a/src/routes/sitemap.xml/+server.ts b/src/routes/sitemap.xml/+server.ts index 64001e3d..ff30ac47 100644 --- a/src/routes/sitemap.xml/+server.ts +++ b/src/routes/sitemap.xml/+server.ts @@ -9,7 +9,7 @@ const pages = [ { title: "/crypto" }, { title: "/etf/etf-providers" }, { title: "/etf/new-launches" }, - { title: "/trending" }, + //{ title: "/trending" }, { title: "/price-alert" }, { title: "/heatmaps" }, { title: "/donation" }, diff --git a/src/routes/stock-screener/+page.svelte b/src/routes/stock-screener/+page.svelte index 5d65aae5..d9bf4d22 100644 --- a/src/routes/stock-screener/+page.svelte +++ b/src/routes/stock-screener/+page.svelte @@ -255,9 +255,9 @@ async function handleCreateStrategy() { async function handleDeleteStrategy() { - const postData = {'strategyId': selectedStrategy}; + const postData = {'strategyId': selectedStrategy, 'path': 'delete-strategy'}; - const response = await fetch(data?.fastifyURL+'/delete-strategy', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -325,10 +325,9 @@ async function createStrategy(event) for (const [key, value] of formData.entries()) { postData[key] = value; } + postData['path'] = 'create-strategy'; - - - const response = await fetch(data?.fastifyURL+'/create-strategy', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -576,9 +575,9 @@ async function handleSave(printToast) { { strategyList.find(item => item.id === selectedStrategy).rules = ruleOfList; - const postData = {'strategyId': selectedStrategy, 'rules': ruleOfList} + const postData = {'strategyId': selectedStrategy, 'rules': ruleOfList, 'path': 'save-strategy'} - const response = await fetch(data?.fastifyURL+'/save-strategy', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" diff --git a/src/routes/stock-screener/workers/downloadWorker.ts b/src/routes/stock-screener/workers/downloadWorker.ts index 689d38fe..4a69c41d 100644 --- a/src/routes/stock-screener/workers/downloadWorker.ts +++ b/src/routes/stock-screener/workers/downloadWorker.ts @@ -64,9 +64,9 @@ const getStockScreenerData = async (rules, apiKey, apiURL) => { }; onmessage = async (event) => { - const { ruleOfList, apiKey, apiURL } = event.data || {}; + const { ruleOfList } = event.data || {}; - const output = await getStockScreenerData(ruleOfList, apiKey, apiURL); + const output = await getStockScreenerData(ruleOfList); const stockScreenerData = output?.filter((item) => Object?.values(item)?.every( diff --git a/src/routes/stocks/[tickerID]/+layout.svelte b/src/routes/stocks/[tickerID]/+layout.svelte index e1f08c8e..9b5acb63 100644 --- a/src/routes/stocks/[tickerID]/+layout.svelte +++ b/src/routes/stocks/[tickerID]/+layout.svelte @@ -112,17 +112,20 @@ function handleTypeOfTrade(state:string) async function toggleUserWatchlist(watchListId: string) { try { const watchlistIndex = userWatchList?.findIndex((item) => item?.id === watchListId); - const postData = { - userId: data?.user?.id, - watchListId, - ticker: $stockTicker, - }; + const postData = { + 'userId': data?.user?.id, + 'watchListId': watchListId, + 'ticker': $stockTicker, + 'path': 'update-watchlist' + }; - const response = await fetch(data?.fastifyURL+'/update-watchlist', { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(postData), - }); + const response = await fetch('/api/fastify-post-data', { + method: 'POST', + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(postData), + }); if (!response.ok) { throw new Error("Network response was not ok"); @@ -144,23 +147,7 @@ function handleTypeOfTrade(state:string) } } - /* -async function fetchPortfolio() -{ - const postData = {'userId': data?.user?.id}; - const response = await fetch(data?.fastifyURL+'/get-portfolio-data', { - method: 'POST', - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify(postData) - }); - - userPortfolio = (await response.json())?.items; - -} -*/ function sendMessage(message) { if (socket && socket.readyState === WebSocket.OPEN) { @@ -276,33 +263,7 @@ async function fetchPortfolio() $: isTickerIncluded = userWatchList?.some((item) => item.user === data?.user?.id && item.ticker?.includes($stockTicker)); - /* -$: { - if(userPortfolio) { - availableCash = userPortfolio?.at(0)?.availableCash; - const userHoldingList = userPortfolio?.at(0)?.holdings || []; - const stockIndex = userHoldingList?.findIndex(stock => stock?.symbol === $stockTicker); - if (stockIndex !== -1) - { - - holdingShares = userHoldingList[stockIndex]['numberOfShares']; - } - else { - holdingShares = 0; - } - } -} - - -$: { - if(typeof window !== 'undefined' && $traded && data?.user && $stockTicker?.length !== 0) - { - fetchPortfolio(); - $traded = false; - } -} -*/ $: charNumber = $screenWidth < 640 ? 12 : 25; diff --git a/src/routes/stocks/[tickerID]/insider/workers/insiderWorker.ts b/src/routes/stocks/[tickerID]/insider/workers/insiderWorker.ts index 91e44941..76f8e95c 100644 --- a/src/routes/stocks/[tickerID]/insider/workers/insiderWorker.ts +++ b/src/routes/stocks/[tickerID]/insider/workers/insiderWorker.ts @@ -62,12 +62,12 @@ function getBarChart(data, dates) { onmessage = async (event: MessageEvent) => { const data = event.data?.message; const rawData = data?.sort( - (a, b) => new Date(b?.transactionDate) - new Date(a?.transactionDate), + (a, b) => new Date(b?.transactionDate) - new Date(a?.transactionDate) ); const latestDate = findLatestDateInPast(rawData); let historicalPrice = event.data?.historicalPrice?.filter( - (item) => new Date(item?.time) >= new Date(latestDate), + (item) => new Date(item?.time) >= new Date(latestDate) ); const dataPoints = historicalPrice?.map(({ close }) => close); @@ -76,9 +76,6 @@ onmessage = async (event: MessageEvent) => { let finalData = { rawData, dataPoints, dates, barChartData }; postMessage({ message: "success", finalData }); - - // Sending data back to the main thread - //postMessage({ message: 'Data received in the worker', ticker, apiURL }); }; export {}; diff --git a/src/routes/tournament-rules/+page.svelte b/src/routes/tournament-rules/+page.svelte deleted file mode 100644 index 4b50d76a..00000000 --- a/src/routes/tournament-rules/+page.svelte +++ /dev/null @@ -1,216 +0,0 @@ - - - - - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} Portfolio Tournament Rules Β· stocknear - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
-

Announcement and Rules

-
- -
- I am thrilled to announce our latest stocknear exclusive Portfolio Tournament! This exciting event offers you the incredible opportunity to win fantastic prizes each and every month. Join us now and experience the thrill of competing for one or more prizes on a regular basis! - - -
-
-
- logo -
- - - - - - - - - - - - - - -
-
- - - -
-
- - -
- -

- Winning Prizes -

- -
- Each month, participants stand a chance to win amazing prizes, including 3x Discounts on the Pro Subscription Plan. The winners will be chosen on the first day of the following month. Don't miss out on this fantastic opportunity to be a winner! -
- - - - - - The Top 3 participant in the - Leaderboard - will be rewarded accordingly with custom badges in their profile. - -
- - -
- -

- Rules -

- - - Participating in the tournament is simple, and we've outlined the rules for you below: - - -
    -
  1. - To join, you must create a User Account and be at least 18 years old. Don't forget to accept our Terms and Conditions to complete your participation. -
  2. -
  3. - One account per participant is allowed. Any form of cheating, including the use of multiple accounts by the same person, is strictly prohibited. -
  4. -
  5. - You'll begin with an initial in-game Budget of $100,000.00 to kickstart your investment journey. -
  6. -
  7. - Utilize your trading skills to buy and sell stocks strategically, aiming to maximize your Return on Investment. -
  8. -
  9. - The ranking system is solely based on your Overall Return, so make every move count. -
  10. -
  11. - Once the tournament concludes, the Top 3 participants with the highest Overall Return will each be awarded a prize for their outstanding performance. -
  12. -
- - - Now that you know the rules, gear up for an exciting investment challenge! Good luck! - - -
- - - - - -
-

- Terms and Conditions of Participation -

- - -
    -
  1. The organizer of the Prize competition is stocknear.
  2. -
  3. Participation is free of charge.
  4. -
  5. - All individuals worldwide who have reached the age of 18 and comply with the laws and regulations of their respective countries are eligible to participate. Persons involved in the conception and implementation of this prize competition are excluded - this explicitly does not apply to voluntary moderators or other voluntary members who have a special status on the platform. -
  6. -
  7. - The prerequisite for participation in the competition is the creation of a portfolio whereby the user can buy and sell shares. Each user starts with a play money of 100,000 $. To be considered in the final draw and eligible for any prizes, participants must make at least one trade (buy or sell shares) during the tournament period. -
  8. -
  9. - The prize competition will take place automated once a month for an indefinite period of time. The potential winners are drawn automatically, randomly on the first day of each month, whereby the chance of winning depends on the overall return of the portfolio. If a participant has collected too little return of the portfolio, the chance can also be 0 percent. -
  10. -
  11. - The prizes to be awarded may change from month to month. -
  12. -
  13. - After the draw, the accounts of the winners will be checked for possible fraud attempts. If no abnormalities are found, the potential winners will be notified by email from stocknear. - If any abnormalities are found, the draw will be repeated. The organizer reserves the right to refuse and reclaim prizes even after the fact and to permanently exclude participants from competitions in case of suspicion of attempted fraud or manipulation for their own benefit or the benefit of third parties as well as to temporarily or permanently block their accounts. -
  14. -
  15. - The potential winner must respond to the respective prize notification within 14 days, - which will be sent via email, in order to claim the prize. - Only a response via email will be considered. - Otherwise, unclaimed prizes will be included in the next monthly draw. -
  16. -
  17. - The organizer points out that the availability and functionality of the prize draw cannot be guaranteed. - The organizer is not responsible for entries not being included due to technical failures or other reasons. - The prize competition may be terminated or removed due to external circumstances and constraints - without any claims arising for the participants against the organizer. -
  18. -
  19. - The organizer reserves the right to change, discontinue, or suspend the game - and the draw in whole or in part without prior notice in the event - of unforeseen circumstances. These circumstances include, but are not limited to, - the appearance of a computer virus, a program error, unauthorized intervention by third parties, - or mechanical or technical problems beyond the control and influence of the organizer. -
  20. -
  21. - The organizer reserves the right to terminate the prize draw at any time without prior notice. - In this case, any outstanding prizes will be properly awarded. -
  22. -
  23. - Should individual provisions of these terms and conditions of participation be or become invalid, - inadmissible, or unenforceable, this shall not affect the validity of the remaining terms - and conditions. In place of the invalid, inadmissible, or unenforceable clause, provisions - shall be deemed to have been agreed upon that come as close as possible to the economic objectives. -
  24. -
  25. - Furthermore, the Imprint, - Terms of Use - and our - - Privacy Policy - - apply. - The applicable law and jurisdiction for this prize draw shall be determined based on the participant's - country of residence. In case of any legal disputes, the competent courts of the participant's - country of residence shall have exclusive jurisdiction. -
  26. -
  27. - The right of recourse to the courts is excluded. -
  28. - -
- -
- - -
- diff --git a/src/routes/watchlist/+page.svelte b/src/routes/watchlist/+page.svelte index 36ea765d..38c611dc 100644 --- a/src/routes/watchlist/+page.svelte +++ b/src/routes/watchlist/+page.svelte @@ -135,9 +135,9 @@ async function createWatchList(event) { for (const [key, value] of formData?.entries()) { postData[key] = value; } - + postData['path'] = 'create-watchlist' try { - const response = await fetch(data?.fastifyURL + '/create-watchlist', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -201,9 +201,10 @@ async function editNameWatchList(event) { for (const [key, value] of formData.entries()) { postData[key] = value; } - + postData['path'] = 'edit-name-watchlist'; + try { - const response = await fetch(data?.fastifyURL + '/edit-name-watchlist', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json" @@ -260,11 +261,11 @@ async function editNameWatchList(event) { async function deleteWatchList(event) { event.preventDefault(); // prevent the default form submission behavior - const postData = {'watchListId': displayWatchList?.id}; + const postData = {'watchListId': displayWatchList?.id, 'path': 'delete-watchlist'}; try { - const response = await fetch(data?.fastifyURL + '/delete-watchlist', { + const response = await fetch('/api/fastify-post-data', { method: 'POST', headers: { "Content-Type": "application/json"