From c9cdd83a580198fd4900bcd3e4e776aa5a155ce6 Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Thu, 24 Apr 2025 17:55:53 -0400 Subject: [PATCH] fix: Update API fetch calls to use absolute URLs for consistency --- src/pages/index.astro | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pages/index.astro b/src/pages/index.astro index a7ad627..1011d3f 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -9,8 +9,11 @@ export interface Props { transactions: Transaction[]; } -// Fetch accounts from API using relative path -const accountsResponse = await fetch(`/api/accounts`); +// Get the base URL from the incoming request +const baseUrl = new URL(Astro.request.url).origin; + +// Fetch accounts from API using absolute URL constructed from the request +const accountsResponse = await fetch(`${baseUrl}/api/accounts`); const accounts: Account[] = await accountsResponse.json(); // Initialize with first account or empty account if none exist @@ -21,10 +24,10 @@ const initialAccount: Account = accounts[0] || { balance: 0 }; -// Fetch initial transactions if we have an account, using relative path +// Fetch initial transactions if we have an account, using absolute URL let initialTransactions: Transaction[] = []; if (initialAccount.id) { - const transactionsResponse = await fetch(`/api/accounts/${initialAccount.id}/transactions`); + const transactionsResponse = await fetch(`${baseUrl}/api/accounts/${initialAccount.id}/transactions`); initialTransactions = await transactionsResponse.json(); } ---