From 9b616f00acb16e02549151d9bd19adb5a5acf9ce Mon Sep 17 00:00:00 2001 From: Alexis Bruneteau Date: Fri, 7 Nov 2025 16:19:05 +0100 Subject: [PATCH] fix: Use Docker service names in BlockchainClient for internal container communication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The backend container needs to reach validators using their Docker service names (validator-1, validator-2, validator-3) instead of localhost:PORT. This fixes the 'validators unreachable' warning on backend startup. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- e-voting-system/backend/blockchain_client.py | 14 +++++---- e-voting-system/frontend/lib/api.ts | 30 +++++++++++++++++--- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/e-voting-system/backend/blockchain_client.py b/e-voting-system/backend/blockchain_client.py index 2443f84..12f9a9e 100644 --- a/e-voting-system/backend/blockchain_client.py +++ b/e-voting-system/backend/blockchain_client.py @@ -49,21 +49,23 @@ class BlockchainClient: """ # Default validator configuration + # Use Docker service names for internal container communication + # For external access (outside Docker), use localhost:PORT DEFAULT_VALIDATORS = [ ValidatorNode( node_id="validator-1", - rpc_url="http://localhost:8001", - p2p_url="http://localhost:30303" + rpc_url="http://validator-1:8001", + p2p_url="http://validator-1:30303" ), ValidatorNode( node_id="validator-2", - rpc_url="http://localhost:8002", - p2p_url="http://localhost:30304" + rpc_url="http://validator-2:8001", + p2p_url="http://validator-2:30303" ), ValidatorNode( node_id="validator-3", - rpc_url="http://localhost:8003", - p2p_url="http://localhost:30305" + rpc_url="http://validator-3:8001", + p2p_url="http://validator-3:30303" ), ] diff --git a/e-voting-system/frontend/lib/api.ts b/e-voting-system/frontend/lib/api.ts index c9d6992..6de59c9 100644 --- a/e-voting-system/frontend/lib/api.ts +++ b/e-voting-system/frontend/lib/api.ts @@ -3,7 +3,9 @@ * Handles all communication with the FastAPI backend */ -const API_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000" +// Use relative paths to go through Next.js proxy routes +// which handle the conversion between camelCase (frontend) and snake_case (backend) +const API_URL = "" export interface ApiResponse { data?: T @@ -25,6 +27,7 @@ export interface VoterProfile { email: string first_name: string last_name: string + has_voted: boolean created_at: string } @@ -148,9 +151,9 @@ export const authApi = { body: JSON.stringify({ email, password, - first_name: firstName, - last_name: lastName, - citizen_id: citizenId, + firstName, + lastName, + citizenId, }), }) }, @@ -229,6 +232,25 @@ export const votesApi = { async getHistory() { return apiRequest("/api/votes/history") }, + + async getBlockchain(electionId: number) { + return apiRequest(`/api/votes/blockchain?election_id=${electionId}`) + }, + + async getResults(electionId: number) { + return apiRequest(`/api/votes/results?election_id=${electionId}`) + }, + + async verifyBlockchain(electionId: number) { + return apiRequest("/api/votes/verify-blockchain", { + method: "POST", + body: JSON.stringify({ election_id: electionId }), + }) + }, + + async getTransactionStatus(transactionId: string, electionId: number) { + return apiRequest(`/api/votes/transaction-status?transaction_id=${transactionId}&election_id=${electionId}`) + }, } /**