Skip to content

Commit 816ae0c

Browse files
authored
Fix a few explorer frontend bugs (#4849)
## Motivation The explorer frontend hardcodes API URLs to `http://localhost:3002`, which only works in local development when both frontend and backend run on localhost. This breaks in production deployments where: - Frontend is served through Kubernetes ingress - Backend API is accessed via the same ingress with `/api` path prefix - Browsers block mixed content (HTTPS frontend → HTTP localhost backend) - CORS issues arise from cross-origin requests The hardcoded URLs prevent the explorer from working in deployed environments. ## Proposal Replace hardcoded absolute URLs with relative paths that work in all environments. Add Vite dev server proxy configuration to maintain local development workflow while using relative paths. This approach works in all environments: - **Local dev**: Vite proxy forwards `/api` → `http://localhost:3002` - **Production**: Kubernetes ingress routes `/api` → backend service ## Test Plan 1. Test production deployment: - Deploy explorer with Kubernetes ingress configured - Verify frontend loads and connects to backend - Confirm no CORS or mixed content errors - Verify all API calls work through ingress ## Release Plan - These changes should be backported to the latest `testnet` branch, then - be released in a validator hotfix.
1 parent 8374555 commit 816ae0c

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

linera-explorer-new/src/hooks/useDatabase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export const useAPI = () => {
99
const [error, setError] = useState<string | null>(null);
1010

1111
useEffect(() => {
12-
// Test API connection
12+
// Test API connection using relative path
1313
const testConnection = async () => {
1414
try {
15-
const response = await fetch('http://localhost:3002/api/health');
15+
const response = await fetch('/api/health');
1616
if (response.ok) {
1717
setIsConnected(true);
1818
} else {

linera-explorer-new/src/utils/database.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Block, BlockInfo, IncomingBundle, PostedMessage, ChainInfo, Operation, Message, Event, OracleResponse, IncomingBundleWithMessages } from '../types/blockchain';
22

3-
const API_BASE_URL = 'http://localhost:3002/api';
3+
// Use relative path for API calls - works in all environments (local dev via proxy, production via ingress)
4+
const API_BASE_URL = '/api';
45

56
export class BlockchainAPI {
67
// Get all blocks with pagination

linera-explorer-new/vite.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import react from '@vitejs/plugin-react'
44
export default defineConfig({
55
plugins: [react()],
66
server: {
7-
port: 3001
7+
port: 3001,
8+
proxy: {
9+
'/api': {
10+
target: 'http://localhost:3002',
11+
changeOrigin: true
12+
}
13+
}
814
}
915
})

0 commit comments

Comments
 (0)