Skip to content

Commit 4c15c69

Browse files
committed
feat: Prioritize env var for WebSocket URL configuration
1 parent 287b269 commit 4c15c69

File tree

1 file changed

+24
-7
lines changed
  • utility_containers/event-puller/dashboard/app

1 file changed

+24
-7
lines changed

utility_containers/event-puller/dashboard/app/page.tsx

+24-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,30 @@ function DashboardContent() {
2929
const searchParams = useSearchParams();
3030

3131
useEffect(() => {
32-
// Get host from query params or use current hostname
33-
const host = searchParams.get('host') || window.location.hostname;
34-
const port = searchParams.get('port') || '8080';
35-
const wsUrl = `ws://${host}:${port}/ws`;
36-
32+
// Get WebSocket URL: Prioritize env var, then query params, then defaults
33+
const envWsUrl = process.env.NEXT_PUBLIC_WS_URL;
34+
const hostQuery = searchParams.get('host');
35+
const portQuery = searchParams.get('port');
36+
37+
let wsUrl: string;
38+
39+
if (envWsUrl) {
40+
wsUrl = envWsUrl;
41+
console.log(`Using WebSocket URL from environment: ${wsUrl}`);
42+
} else if (hostQuery) {
43+
const port = portQuery || '8080';
44+
wsUrl = `ws://${hostQuery}:${port}/ws`;
45+
console.log(`Using WebSocket URL from query params: ${wsUrl}`);
46+
} else {
47+
// Default for cases where env var and query params are not set
48+
// This might happen in production deployments or if .env.local is missing
49+
const defaultHost = window.location.hostname;
50+
const defaultPort = '8080'; // Assuming backend runs on 8080 by default
51+
wsUrl = `ws://${defaultHost}:${defaultPort}/ws`;
52+
console.log(`Using default WebSocket URL based on hostname: ${wsUrl}`);
53+
}
54+
3755
connectWebSocket(wsUrl);
38-
3956
return () => {
4057
if (ws.current) {
4158
ws.current.close();
@@ -197,4 +214,4 @@ const Dashboard = dynamic(() => Promise.resolve(DashboardContent), {
197214
ssr: false,
198215
});
199216

200-
export default Dashboard;
217+
export default Dashboard;

0 commit comments

Comments
 (0)