feat: implement HTTP polling to bypass WebSocket issue
The WebSocket closes immediately with code 1006 due to nginx/proxy issues. This implementation completely bypasses WebSocket for terminal output by using HTTP polling instead. Architecture: - Server buffers PTY output in memory (outputBuffer array) - Frontend polls every 100ms via GET /terminals/:id/output?since=N - Output entries have monotonically increasing index - Old output is automatically cleaned up after 5 minutes - Commands sent via HTTP POST (already implemented) Changes: - terminal-service.js: Added bufferOutput(), getTerminalOutput() - terminal.js: Added startPolling(), stopPolling(), sendTerminalResize() - server.js: Added GET /terminals/:id/output and POST /terminals/:id/resize - No WebSocket needed for output display (keeps legacy compatibility) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
40
server.js
40
server.js
@@ -1528,6 +1528,46 @@ app.post('/claude/api/terminals/:id/input', requireAuth, (req, res) => {
|
||||
res.status(500).json({ error: 'Failed to send input' });
|
||||
}
|
||||
});
|
||||
|
||||
// Get terminal output via HTTP polling (bypasses WebSocket issue)
|
||||
app.get('/claude/api/terminals/:id/output', requireAuth, (req, res) => {
|
||||
try {
|
||||
const sinceIndex = parseInt(req.query.since) || 0;
|
||||
const result = terminalService.getTerminalOutput(req.params.id, sinceIndex);
|
||||
|
||||
if (result.success) {
|
||||
res.json(result);
|
||||
} else {
|
||||
res.status(404).json({ error: result.error });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error getting terminal output:', error);
|
||||
res.status(500).json({ error: 'Failed to get output' });
|
||||
}
|
||||
});
|
||||
|
||||
// Resize terminal via HTTP
|
||||
app.post('/claude/api/terminals/:id/resize', requireAuth, (req, res) => {
|
||||
try {
|
||||
const { cols, rows } = req.body;
|
||||
|
||||
if (!cols || !rows) {
|
||||
res.status(400).json({ error: 'Missing cols or rows parameter' });
|
||||
return;
|
||||
}
|
||||
|
||||
const result = terminalService.resizeTerminal(req.params.id, cols, rows);
|
||||
|
||||
if (result.success) {
|
||||
res.json({ success: true });
|
||||
} else {
|
||||
res.status(404).json({ error: result.error });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error resizing terminal:', error);
|
||||
res.status(500).json({ error: 'Failed to resize terminal' });
|
||||
}
|
||||
});
|
||||
|
||||
// Get recent directories for terminal picker
|
||||
app.get('/claude/api/files/recent-dirs', requireAuth, (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user