@@ -5,7 +5,13 @@ import { HiOutlineEye, HiOutlineTrash, HiSearch, HiPlus, HiTrendingUp, HiTrendin
5
5
import { Card , Text , Metric , Badge , ProgressBar } from '@tremor/react' ;
6
6
import { AreaChart , Area , XAxis , YAxis , CartesianGrid , Tooltip , ResponsiveContainer } from 'recharts' ;
7
7
8
- const API_BASE_URL = 'http://localhost:5000/api' ;
8
+ const API_BASE_URL = import . meta. env . VITE_API_BASE_URL || 'https://portfolio-tracker-backend-y7ne.onrender.com/api' ;
9
+
10
+ // Create axios instance with base URL
11
+ const api = axios . create ( {
12
+ baseURL : API_BASE_URL ,
13
+ timeout : 10000
14
+ } ) ;
9
15
10
16
const Watchlist = ( ) => {
11
17
const [ watchlist , setWatchlist ] = useState ( [ ] ) ;
@@ -43,8 +49,8 @@ const Watchlist = () => {
43
49
44
50
const fetchWatchlist = async ( ) => {
45
51
try {
46
- console . log ( 'Fetching watchlist...' ) ;
47
- const response = await axios . get ( ` ${ API_BASE_URL } /watchlist` ) ;
52
+ console . log ( 'Fetching watchlist from:' , API_BASE_URL ) ;
53
+ const response = await api . get ( ' /watchlist' ) ;
48
54
console . log ( 'Watchlist response:' , response . data ) ;
49
55
setWatchlist ( response . data ) ;
50
56
setLoading ( false ) ;
@@ -58,7 +64,7 @@ const Watchlist = () => {
58
64
const syncPortfolioStocks = async ( ) => {
59
65
try {
60
66
console . log ( 'Syncing portfolio stocks...' ) ;
61
- await axios . post ( ` ${ API_BASE_URL } /watchlist/sync-portfolio` ) ;
67
+ await api . post ( ' /watchlist/sync-portfolio' ) ;
62
68
await fetchWatchlist ( ) ;
63
69
} catch ( error ) {
64
70
console . error ( 'Error syncing portfolio stocks:' , error ) ;
@@ -70,7 +76,7 @@ const Watchlist = () => {
70
76
e . preventDefault ( ) ;
71
77
try {
72
78
console . log ( 'Adding stock:' , newStock ) ;
73
- await axios . post ( ` ${ API_BASE_URL } /watchlist` , newStock ) ;
79
+ await api . post ( ' /watchlist' , newStock ) ;
74
80
setShowAddModal ( false ) ;
75
81
setNewStock ( { name : '' , ticker : '' , target_price : '' } ) ;
76
82
await fetchWatchlist ( ) ;
@@ -84,7 +90,7 @@ const Watchlist = () => {
84
90
if ( window . confirm ( 'Are you sure you want to remove this stock from your watchlist?' ) ) {
85
91
try {
86
92
console . log ( 'Deleting stock:' , id ) ;
87
- await axios . delete ( `${ API_BASE_URL } /watchlist/${ id } ` ) ;
93
+ await api . delete ( `/watchlist/${ id } ` ) ;
88
94
await fetchWatchlist ( ) ;
89
95
} catch ( error ) {
90
96
console . error ( 'Error deleting stock:' , error ) ;
@@ -97,7 +103,7 @@ const Watchlist = () => {
97
103
e . preventDefault ( ) ;
98
104
try {
99
105
console . log ( 'Updating stock:' , selectedStock ) ;
100
- await axios . put ( `${ API_BASE_URL } /watchlist/${ selectedStock . id } ` , {
106
+ await api . put ( `/watchlist/${ selectedStock . id } ` , {
101
107
target_price : selectedStock . target_price
102
108
} ) ;
103
109
setShowUpdateModal ( false ) ;
@@ -113,7 +119,7 @@ const Watchlist = () => {
113
119
setSelectedStock ( stock ) ;
114
120
setShowViewModal ( true ) ;
115
121
try {
116
- const response = await axios . get ( `${ API_BASE_URL } /watchlist/${ stock . id } /history` ) ;
122
+ const response = await api . get ( `/watchlist/${ stock . id } /history` ) ;
117
123
setPriceHistory ( response . data . map ( item => ( {
118
124
...item ,
119
125
date : new Date ( item . timestamp ) . toLocaleDateString ( ) ,
0 commit comments