Fix setup/loading flow and WebSocket connection
1. Setup redirect flow (setup -> loading -> login): - Add /loading to exempt paths - Redirect setup to login after completion - Redirect loading to login when initialization complete 2. Close pages after completion: - Block access to /setup after setup is done - Block access to /loading after initialization complete - Proper redirect handling prevents re-access 3. Fix WebSocket 403 error: - Change /ws/progress to /ws/connect (correct endpoint) - Add /ws/connect to exempt paths - Subscribe to 'system' room for progress updates - Fix message data handling format
This commit is contained in:
@@ -294,13 +294,19 @@
|
||||
|
||||
function connectWebSocket() {
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const wsUrl = `${protocol}//${window.location.host}/ws/progress`;
|
||||
const wsUrl = `${protocol}//${window.location.host}/ws/connect`;
|
||||
|
||||
ws = new WebSocket(wsUrl);
|
||||
|
||||
ws.onopen = () => {
|
||||
console.log('WebSocket connected');
|
||||
updateConnectionStatus(true);
|
||||
|
||||
// Subscribe to system room for progress updates
|
||||
ws.send(JSON.stringify({
|
||||
action: 'join',
|
||||
room: 'system'
|
||||
}));
|
||||
};
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
@@ -340,8 +346,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleProgressUpdate(data) {
|
||||
const { type, status, title, message, percent, current, total, metadata } = data;
|
||||
function handleProgressUpdate(message) {
|
||||
// Handle WebSocket message format: { type: string, data: {...} }
|
||||
const data = message.data || message;
|
||||
const { type, status, title, message: msg, percent, current, total, metadata } = data;
|
||||
|
||||
// Determine step ID based on type and metadata
|
||||
let stepId = metadata?.step_id || type;
|
||||
@@ -351,7 +359,7 @@
|
||||
createStep(stepId, title || stepTitles[stepId] || stepId);
|
||||
}
|
||||
|
||||
updateStep(stepId, status, message, percent, current, total);
|
||||
updateStep(stepId, status, msg, percent, current, total);
|
||||
|
||||
// Check for completion
|
||||
if (metadata?.initialization_complete) {
|
||||
@@ -360,7 +368,7 @@
|
||||
|
||||
// Handle errors
|
||||
if (status === 'failed') {
|
||||
showError(message || 'An error occurred during initialization');
|
||||
showError(msg || 'An error occurred during initialization');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,7 +482,7 @@
|
||||
}
|
||||
|
||||
function continueToApp() {
|
||||
window.location.href = '/';
|
||||
window.location.href = '/login';
|
||||
}
|
||||
|
||||
// Start WebSocket connection when page loads
|
||||
|
||||
Reference in New Issue
Block a user