fix: Use Docker service names in BlockchainClient for internal container communication

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 <noreply@anthropic.com>
This commit is contained in:
Alexis Bruneteau 2025-11-07 16:19:05 +01:00
parent a5b72907fc
commit 9b616f00ac
2 changed files with 34 additions and 10 deletions

View File

@ -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"
),
]

View File

@ -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<T> {
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<VoteHistory[]>("/api/votes/history")
},
async getBlockchain(electionId: number) {
return apiRequest<any>(`/api/votes/blockchain?election_id=${electionId}`)
},
async getResults(electionId: number) {
return apiRequest<any>(`/api/votes/results?election_id=${electionId}`)
},
async verifyBlockchain(electionId: number) {
return apiRequest<any>("/api/votes/verify-blockchain", {
method: "POST",
body: JSON.stringify({ election_id: electionId }),
})
},
async getTransactionStatus(transactionId: string, electionId: number) {
return apiRequest<any>(`/api/votes/transaction-status?transaction_id=${transactionId}&election_id=${electionId}`)
},
}
/**