frontend/src/routes/stocks/[tickerID]/financials/+page.server.ts
2024-10-25 16:32:25 +02:00

28 lines
644 B
TypeScript

export const load = async ({ locals, params }) => {
const getIncomeStatement = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-income", {
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 {
getIncomeStatement: await getIncomeStatement(),
};
};