fix: use request URL for base URL in stock detail loader

- Fix TypeError from undefined BASE_URL in loader
- Use request.url to construct base URL dynamically
This commit is contained in:
2026-05-14 11:04:17 +02:00
parent 2e22fd5635
commit 834a427c18
+7 -3
View File
@@ -10,16 +10,20 @@ interface LoaderData {
orders: any[];
}
export async function loader({ params }: { params: { ticker: string } }) {
export async function loader({ params, request }: { params: { ticker: string }; request: Request }) {
const ticker = params.ticker?.toUpperCase() || "";
// Build base URL from request for server-side fetches
const url = new URL(request.url);
const baseUrl = `${url.protocol}//${url.host}`;
// Fetch position
const posRes = await fetch(`${process.env.BASE_URL}/api/alpaca/positions`);
const posRes = await fetch(`${baseUrl}/api/alpaca/positions`);
const positions = posRes.ok ? await posRes.json() : [];
const position = positions.find((p: any) => p.ticker === ticker)?.qty ?? null;
// Fetch orders
const ordRes = await fetch(`${process.env.BASE_URL}/api/alpaca/orders`);
const ordRes = await fetch(`${baseUrl}/api/alpaca/orders`);
const ordersData = ordRes.ok ? await ordRes.json() : { orders: [] };
const orders = ordersData.orders?.filter((o: any) => o.symbol === ticker) || [];