mirror of
https://github.com/siteboon/claudecodeui.git
synced 2025-12-13 13:49:43 +00:00
refactor: remove unused /api/config endpoint and update WebSocket connection logic
This commit is contained in:
@@ -270,17 +270,8 @@ app.use(express.static(path.join(__dirname, '../dist'), {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// API Routes (protected)
|
// API Routes (protected)
|
||||||
app.get('/api/config', authenticateToken, (req, res) => {
|
// /api/config endpoint removed - no longer needed
|
||||||
const host = req.headers.host || `${req.hostname}:${PORT}`;
|
// Frontend now uses window.location for WebSocket URLs
|
||||||
const protocol = req.protocol === 'https' || req.get('x-forwarded-proto') === 'https' ? 'wss' : 'ws';
|
|
||||||
|
|
||||||
console.log('Config API called - Returning host:', host, 'Protocol:', protocol);
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
serverPort: PORT,
|
|
||||||
wsUrl: `${protocol}://${host}`
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// System update endpoint
|
// System update endpoint
|
||||||
app.post('/api/system/update', authenticateToken, async (req, res) => {
|
app.post('/api/system/update', authenticateToken, async (req, res) => {
|
||||||
|
|||||||
@@ -382,40 +382,26 @@ function Shell({ selectedProject, selectedSession, isActive, initialCommand, isP
|
|||||||
if (isConnecting || isConnected) return;
|
if (isConnecting || isConnected) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get authentication token
|
const isPlatform = import.meta.env.VITE_IS_PLATFORM === 'true';
|
||||||
const token = localStorage.getItem('auth-token');
|
|
||||||
if (!token) {
|
|
||||||
console.error('No authentication token found for Shell WebSocket connection');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch server configuration to get the correct WebSocket URL
|
// Construct WebSocket URL
|
||||||
let wsBaseUrl;
|
let wsUrl;
|
||||||
try {
|
|
||||||
const configResponse = await fetch('/api/config', {
|
|
||||||
headers: {
|
|
||||||
'Authorization': `Bearer ${token}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const config = await configResponse.json();
|
|
||||||
wsBaseUrl = config.wsUrl;
|
|
||||||
|
|
||||||
// If the config returns localhost but we're not on localhost, use current host but with API server port
|
if (isPlatform) {
|
||||||
if (wsBaseUrl.includes('localhost') && !window.location.hostname.includes('localhost')) {
|
// Platform mode: Use same domain as the page (goes through proxy)
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
||||||
// For development, API server is typically on port 3002 when Vite is on 3001
|
|
||||||
const apiPort = window.location.port === '3001' ? '3002' : window.location.port;
|
|
||||||
wsBaseUrl = `${protocol}//${window.location.hostname}:${apiPort}`;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
// For development, API server is typically on port 3002 when Vite is on 3001
|
wsUrl = `${protocol}//${window.location.host}/shell`;
|
||||||
const apiPort = window.location.port === '3001' ? '3002' : window.location.port;
|
} else {
|
||||||
wsBaseUrl = `${protocol}//${window.location.hostname}:${apiPort}`;
|
// OSS mode: Connect to same host:port that served the page
|
||||||
}
|
const token = localStorage.getItem('auth-token');
|
||||||
|
if (!token) {
|
||||||
|
console.error('No authentication token found for Shell WebSocket connection');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Include token in WebSocket URL as query parameter
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
const wsUrl = `${wsBaseUrl}/shell?token=${encodeURIComponent(token)}`;
|
wsUrl = `${protocol}//${window.location.host}/shell?token=${encodeURIComponent(token)}`;
|
||||||
|
}
|
||||||
|
|
||||||
ws.current = new WebSocket(wsUrl);
|
ws.current = new WebSocket(wsUrl);
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export const api = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Protected endpoints
|
// Protected endpoints
|
||||||
config: () => authenticatedFetch('/api/config'),
|
// config endpoint removed - no longer needed (frontend uses window.location)
|
||||||
projects: () => authenticatedFetch('/api/projects'),
|
projects: () => authenticatedFetch('/api/projects'),
|
||||||
sessions: (projectName, limit = 5, offset = 0) =>
|
sessions: (projectName, limit = 5, offset = 0) =>
|
||||||
authenticatedFetch(`/api/projects/${projectName}/sessions?limit=${limit}&offset=${offset}`),
|
authenticatedFetch(`/api/projects/${projectName}/sessions?limit=${limit}&offset=${offset}`),
|
||||||
|
|||||||
@@ -21,49 +21,27 @@ export function useWebSocket() {
|
|||||||
|
|
||||||
const connect = async () => {
|
const connect = async () => {
|
||||||
try {
|
try {
|
||||||
// Get authentication token (skip in platform mode)
|
|
||||||
let token = null;
|
|
||||||
const isPlatform = import.meta.env.VITE_IS_PLATFORM === 'true';
|
const isPlatform = import.meta.env.VITE_IS_PLATFORM === 'true';
|
||||||
|
|
||||||
if (!isPlatform) {
|
// Construct WebSocket URL
|
||||||
token = localStorage.getItem('auth-token');
|
let wsUrl;
|
||||||
|
|
||||||
|
if (isPlatform) {
|
||||||
|
// Platform mode: Use same domain as the page (goes through proxy)
|
||||||
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
|
wsUrl = `${protocol}//${window.location.host}/ws`;
|
||||||
|
} else {
|
||||||
|
// OSS mode: Connect to same host:port that served the page
|
||||||
|
const token = localStorage.getItem('auth-token');
|
||||||
if (!token) {
|
if (!token) {
|
||||||
console.warn('No authentication token found for WebSocket connection');
|
console.warn('No authentication token found for WebSocket connection');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch server configuration to get the correct WebSocket URL
|
|
||||||
let wsBaseUrl;
|
|
||||||
try {
|
|
||||||
const configResponse = await fetch('/api/config', {
|
|
||||||
headers: token ? {
|
|
||||||
'Authorization': `Bearer ${token}`
|
|
||||||
} : {}
|
|
||||||
});
|
|
||||||
const config = await configResponse.json();
|
|
||||||
wsBaseUrl = config.wsUrl;
|
|
||||||
|
|
||||||
// If the config returns localhost but we're not on localhost, use current host but with API server port
|
|
||||||
if (wsBaseUrl.includes('localhost') && !window.location.hostname.includes('localhost')) {
|
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
||||||
// For development, API server is typically on port 3002 when Vite is on 3001
|
|
||||||
const apiPort = window.location.port === '3001' ? '3002' : window.location.port;
|
|
||||||
wsBaseUrl = `${protocol}//${window.location.hostname}:${apiPort}`;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Could not fetch server config, falling back to current host with API server port');
|
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
// For development, API server is typically on port 3002 when Vite is on 3001
|
wsUrl = `${protocol}//${window.location.host}/ws?token=${encodeURIComponent(token)}`;
|
||||||
const apiPort = window.location.port === '3001' ? '3002' : window.location.port;
|
|
||||||
wsBaseUrl = `${protocol}//${window.location.hostname}:${apiPort}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include token in WebSocket URL as query parameter (only in OSS mode)
|
|
||||||
let wsUrl = `${wsBaseUrl}/ws`;
|
|
||||||
if (token) {
|
|
||||||
wsUrl += `?token=${encodeURIComponent(token)}`;
|
|
||||||
}
|
|
||||||
const websocket = new WebSocket(wsUrl);
|
const websocket = new WebSocket(wsUrl);
|
||||||
|
|
||||||
websocket.onopen = () => {
|
websocket.onopen = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user