Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ VITE_APP_ENV="development" # development | staging | production

# ─── Backend API ───────────────────────────────────────────────────────────────
VITE_API_BASE_URL="http://localhost:8000"
VITE_MARKET_API_BASE_URL="http://localhost:8001"
VITE_MARKET_WS_BASE_URL="ws://localhost:8001"
16 changes: 16 additions & 0 deletions src/lib/api.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@ import axios from 'axios';
import { useUserStore } from '@/stores/userStore';

const API_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000';
const MARKET_API_URL = import.meta.env.VITE_MARKET_API_BASE_URL || 'http://localhost:8001';

export const apiClient = axios.create({
baseURL: API_URL,
withCredentials: true, // Crucial for sending/receiving the HttpOnly refresh token cookie
timeout: 5000,
});

export const marketApiClient = axios.create({
baseURL: MARKET_API_URL,
withCredentials: true,
timeout: 5000,
});

// Request Interceptor for marketApiClient: Attach access token
marketApiClient.interceptors.request.use((config) => {
const token = useUserStore.getState().accessToken;
if (token && config.headers) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});

// Request Interceptor: Attach the access token if available
apiClient.interceptors.request.use((config) => {
const token = useUserStore.getState().accessToken;
Expand Down
6 changes: 4 additions & 2 deletions src/pages/LiveMarketDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React, { useState, useEffect } from 'react';
import '@/styles/components/live-market.css';

const MARKET_WS_URL = import.meta.env.VITE_MARKET_WS_BASE_URL || 'ws://localhost:8001';

export const LiveMarketDashboard: React.FC = () => {
const [marketData, setMarketData] = useState({ gainers: [], losers: [] });
const [activeTab, setActiveTab] = useState('Stocks');

useEffect(() => {
// 1. Connect to the FastAPI WebSocket Bridge
const ws = new WebSocket("ws://localhost:8000/dashboard/ws/market");
// 1. Connect to the Market Service WebSocket
const ws = new WebSocket(`${MARKET_WS_URL}/dashboard/ws/market`);

// 2. Listen for live updates being pushed from FastAPI
ws.onmessage = (event) => {
Expand Down
Loading