[8c4ad8]: / web / server / server.js

Download this file

231 lines (203 with data), 9.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
* DNAnalyzer Server Page JavaScript
* Copyright © 2025 Piyush Acharya
*/
document.addEventListener('DOMContentLoaded', function() {
// Mobile navigation toggle
const mobileToggle = document.getElementById('mobileToggle');
const navLinks = document.getElementById('navLinks');
if (mobileToggle && navLinks) {
mobileToggle.addEventListener('click', function() {
navLinks.classList.toggle('active');
mobileToggle.querySelector('i').classList.toggle('fa-bars');
mobileToggle.querySelector('i').classList.toggle('fa-times');
});
}
// Navbar scroll behavior
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', function() {
if (window.scrollY > 100) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// Server status check
const serverStatusElement = document.getElementById('server-status');
let statusCheckInterval;
let retryCount = 0;
const MAX_RETRIES = 3;
const SERVER_PORT = 8080;
// Copy commands functionality
window.copyCloneCommand = function() {
copyToClipboard('git clone https://github.com/VerisimilitudeX/DNAnalyzer.git && cd DNAnalyzer', 0);
};
window.copyChmodCommand = function() {
copyToClipboard('chmod +x ./gradlew', 1);
};
window.copyBuildCommand = function() {
copyToClipboard('./gradlew clean bootJar', 2);
};
window.copyRunCommand = function() {
copyToClipboard('java -jar build/libs/DNAnalyzer.jar', 3);
};
function copyToClipboard(text, buttonIndex) {
navigator.clipboard.writeText(text).then(() => {
const buttons = document.querySelectorAll('.copy-button');
const button = buttons[buttonIndex];
button.textContent = 'Copied!';
button.classList.add('success');
setTimeout(() => {
button.textContent = 'Copy';
button.classList.remove('success');
}, 2000);
}).catch(() => {
const buttons = document.querySelectorAll('.copy-button');
const button = buttons[buttonIndex];
button.textContent = 'Failed';
button.classList.add('error');
setTimeout(() => {
button.textContent = 'Copy';
button.classList.remove('error');
}, 2000);
});
}
// Server status check with retry logic
async function checkServerStatus(isInitialCheck = false) {
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
// Try the API status endpoint first
const response = await fetch(`http://localhost:${SERVER_PORT}/api/v1/status`, {
method: 'GET',
signal: controller.signal,
headers: {
'Accept': 'application/json',
}
});
clearTimeout(timeoutId);
retryCount = 0; // Reset retry count on success
serverStatusElement.innerHTML = `
<div class="status-indicator online">
<div class="status-dot"></div>
<div class="status-details">
<div class="status-main">Server Online</div>
<div class="status-info">
<span>Status: Running</span>
<span>Last checked: ${new Date().toLocaleTimeString()}</span>
<span>Ready to process DNA sequences</span>
</div>
</div>
</div>
`;
return true;
} catch (error) {
// Try root URL as fallback
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
const response = await fetch(`http://localhost:${SERVER_PORT}/`, {
method: 'GET',
signal: controller.signal
});
clearTimeout(timeoutId);
if (response.ok || response.status === 404) {
// Even a 404 means the server is running
retryCount = 0;
serverStatusElement.innerHTML = `
<div class="status-indicator online">
<div class="status-dot"></div>
<div class="status-details">
<div class="status-main">Server Online</div>
<div class="status-info">
<span>Status: Running</span>
<span>Last checked: ${new Date().toLocaleTimeString()}</span>
<span>Ready to process DNA sequences</span>
</div>
</div>
</div>
`;
return true;
}
throw new Error('Server not responding correctly');
} catch (fallbackError) {
retryCount++;
const isMaxRetries = retryCount >= MAX_RETRIES;
serverStatusElement.innerHTML = `
<div class="status-indicator offline">
<div class="status-dot"></div>
<div class="status-details">
<div class="status-main">Server Offline</div>
<div class="status-info">
<span>Last checked: ${new Date().toLocaleTimeString()}</span>
${isInitialCheck ? '<span>Follow the setup steps above to start the server</span>' : ''}
${!isInitialCheck && !isMaxRetries ? `<span>Retrying... (${retryCount}/${MAX_RETRIES})</span>` : ''}
${isMaxRetries ? '<span>Max retries reached. Check server setup instructions above.</span>' : ''}
</div>
</div>
</div>
`;
if (isMaxRetries) {
clearInterval(statusCheckInterval);
showTroubleshooting();
}
return false;
}
}
}
function showTroubleshooting() {
const troubleshootingSection = document.getElementById('troubleshooting');
if (troubleshootingSection) {
troubleshootingSection.classList.add('active');
troubleshootingSection.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
// Initialize status checking
async function initializeStatusCheck() {
const isOnline = await checkServerStatus(true);
if (!isOnline) {
// If offline on first check, start checking more frequently initially
statusCheckInterval = setInterval(() => checkServerStatus(), 5000);
// After 30 seconds, switch to normal interval if server is still offline
setTimeout(() => {
clearInterval(statusCheckInterval);
statusCheckInterval = setInterval(() => checkServerStatus(), 30000);
}, 30000);
} else {
// If online, check every 30 seconds
statusCheckInterval = setInterval(() => checkServerStatus(), 30000);
}
}
// Start status checking
initializeStatusCheck();
// Cleanup on page unload
window.addEventListener('unload', () => {
if (statusCheckInterval) {
clearInterval(statusCheckInterval);
}
});
// Add animated appearance for steps
const animateSteps = () => {
const stepCards = document.querySelectorAll('.step-card');
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.style.opacity = 1;
entry.target.style.transform = 'translateY(0)';
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1
});
stepCards.forEach((card, index) => {
card.style.opacity = 0;
card.style.transform = 'translateY(20px)';
card.style.transition = 'opacity 0.5s ease, transform 0.5s ease';
card.style.transitionDelay = `${index * 0.1}s`;
observer.observe(card);
});
};
// Initialize animations
setTimeout(animateSteps, 500);
});