Skip to content

Commit a4029c8

Browse files
dawidclaude
andcommitted
Integrate dashboard API into main container
Fix 502 Bad Gateway error by properly integrating dashboard: - Copy dashboard files to container at build time - Install dashboard dependencies (express, socket.io, cors) - Start dashboard API on port 3001 in run.sh - Add simple HTML dashboard page for testing - Set correct port separation (MCP:3000, Dashboard:3001) - Add dashboard process management This resolves the 502 error by ensuring the dashboard API actually runs inside the addon container. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c2e94cd commit a4029c8

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,22 @@ RUN npm install -g @modelcontextprotocol/server-filesystem
3434
# Switch back to root for remaining setup
3535
USER root
3636

37+
# Install dashboard dependencies
38+
COPY dashboard/api/package.json /tmp/dashboard-api-package.json
39+
RUN cd /tmp && npm install express socket.io cors --production && \
40+
mkdir -p /dashboard/api/node_modules && \
41+
cp -r node_modules/* /dashboard/api/node_modules/ && \
42+
rm -rf /tmp/node_modules /tmp/dashboard-api-package.json
43+
3744
# Copy scripts and configuration
3845
COPY scripts/ /opt/scripts/
3946
COPY tcp-wrapper.js /tcp-wrapper.js
4047
COPY run.sh /run.sh
4148
COPY entrypoint.sh /entrypoint.sh
4249

50+
# Copy dashboard files
51+
COPY dashboard/ /dashboard/
52+
4353
# Set permissions
4454
RUN chmod +x /run.sh /entrypoint.sh /opt/scripts/*.sh
4555

dashboard/api/server.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,37 @@ app.use(cors({
2323
}));
2424
app.use(express.json());
2525

26-
// Handle Ingress routing
27-
app.use('/dashboard', express.static(path.join(__dirname, '../frontend/build')));
28-
app.get('/dashboard/*', (req, res) => {
29-
res.sendFile(path.join(__dirname, '../frontend/build', 'index.html'));
26+
// Serve a simple dashboard page for now
27+
app.get('/', (req, res) => {
28+
res.send(`
29+
<html>
30+
<head><title>HA MCP Dashboard</title></head>
31+
<body>
32+
<h1>Home Assistant MCP Server Dashboard</h1>
33+
<p>Dashboard API is running!</p>
34+
<h2>Available Endpoints:</h2>
35+
<ul>
36+
<li><a href="/api/health">/api/health</a> - System health</li>
37+
<li><a href="/api/metrics">/api/metrics</a> - System metrics</li>
38+
<li><a href="/api/cache">/api/cache</a> - Cache statistics</li>
39+
<li><a href="/api/logs">/api/logs</a> - Recent logs</li>
40+
<li><a href="/api/dashboard">/api/dashboard</a> - Complete dashboard data</li>
41+
</ul>
42+
<p>Status: <span id="status">Checking...</span></p>
43+
<script>
44+
fetch('/api/health').then(r => r.json()).then(data => {
45+
document.getElementById('status').textContent = data.overall_status || 'OK';
46+
}).catch(e => {
47+
document.getElementById('status').textContent = 'Error: ' + e.message;
48+
});
49+
</script>
50+
</body>
51+
</html>
52+
`);
3053
});
3154

3255
// Configuration
33-
const PORT = process.env.DASHBOARD_PORT || 3000;
56+
const PORT = process.env.DASHBOARD_PORT || 3001; // Dashboard on 3001, MCP on 3000
3457
const SCRIPTS_PATH = path.join(__dirname, '../../scripts');
3558
const UPDATE_INTERVAL = 5000; // 5 seconds
3659

run.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ if [[ -f "/opt/scripts/monitor.sh" ]]; then
113113
(/opt/scripts/monitor.sh 2>/dev/null) &
114114
fi
115115

116+
# Start Dashboard API on port 3001 if files exist
117+
if [[ -f "/dashboard/api/server.js" ]]; then
118+
bashio::log.info "Starting Dashboard API on port 3001..."
119+
cd /dashboard/api
120+
nohup node server.js >/tmp/dashboard.log 2>&1 &
121+
DASHBOARD_PID=$!
122+
bashio::log.info "Dashboard API started with PID: $DASHBOARD_PID"
123+
cd /
124+
fi
125+
116126
# Run initial health check
117127
if [[ -f "/opt/scripts/health-check.sh" ]]; then
118128
bashio::log.info "Running initial health check..."

0 commit comments

Comments
 (0)