1
+ # main.py
2
+
1
3
from fastapi import FastAPI
2
4
from fastapi .middleware .cors import CORSMiddleware
3
5
@@ -25,10 +27,10 @@ async def lifespan(app: FastAPI):
25
27
load_dotenv ()
26
28
27
29
# Get Redis connection information from environment variables
28
- redis_host :str = os .getenv ("REDIS_HOST" , "localhost" )
30
+ redis_host :str = os .getenv ("REDIS_HOST" , "db-redis" ) # Use new service name
29
31
redis_port :int = int (os .getenv ("REDIS_PORT" , 6379 ))
30
- redis_database :int = int (os .getenv ("REDIS_DATABASE " , 0 ))
31
- update_interval_in_seconds :int = int (os .getenv ("UPDATE_INTERVAL_IN_SECONDS " , 1 ))
32
+ redis_database :int = int (os .getenv ("REDIS_DB " , 0 ))
33
+ update_interval_in_seconds :int = int (os .getenv ("REDIS_UDPATE_INTERVAL_IN_SECONDS " , 1 ))
32
34
console .log (f"Setting up the Redis database at { redis_host } :{ redis_port } /{ redis_database } (update interval: { update_interval_in_seconds } seconds)" )
33
35
start_fetch_and_store_market_data (redis_host = redis_host ,
34
36
redis_port = redis_port ,
@@ -69,7 +71,7 @@ async def lifespan(app: FastAPI):
69
71
console .log (
70
72
f"Test account created because it didn't exist [bold](UUID: { user_uuid } )[/bold]" )
71
73
72
- # Manully insert the balance for the test account
74
+ # Manually insert the balance for the test account
73
75
from models import Balance
74
76
db = SessionLocal ()
75
77
new_balance = Balance (user_id = new_user .id ,
@@ -85,11 +87,13 @@ async def lifespan(app: FastAPI):
85
87
app = FastAPI (lifespan = lifespan )
86
88
87
89
allowed_origins : list = [
88
- "http://localhost:5173" ,
90
+ "http://localhost:5173" , # Vite dev server default
91
+ "http://localhost:4173" , # Vite preview default
92
+ "http://frontend:4173" # Frontend service in Docker
89
93
]
90
94
app .add_middleware (
91
95
CORSMiddleware ,
92
- allow_origins = [ "*" ] ,
96
+ allow_origins = allowed_origins ,
93
97
allow_credentials = True ,
94
98
allow_methods = ["*" ],
95
99
allow_headers = ["*" ],
0 commit comments