Add frontend speed test application and server setup

* Introduced a new HTML frontend for network speed testing with a responsive UI
* Implemented backend server functionality to serve the frontend and handle speed test APIs
* Added speed test logic for downloading and uploading data, including progress tracking and result validation
* Created README-SPEEDTEST.md for documentation on application architecture, setup, and usage.
* Updated package.json to include necessary scripts and dependencies for development and testing
This commit is contained in:
2025-11-21 04:56:18 -05:00
parent 3a3b85f138
commit 21b9e52f40
22 changed files with 1152 additions and 60 deletions

59
serve-frontend.ts Normal file
View File

@@ -0,0 +1,59 @@
#!/usr/bin/env bun
import { readFile } from 'fs/promises';
import { LoggerFactory } from '@techniker-me/logger';
const logger = LoggerFactory.getLogger('FrontendServer');
const PORT = 3001;
const server = Bun.serve({
port: PORT,
async fetch(request) {
const url = new URL(request.url);
// Serve the HTML frontend
if (url.pathname === '/' || url.pathname === '/index.html') {
try {
const html = await readFile('./frontend.html', 'utf-8');
return new Response(html, {
headers: {
'Content-Type': 'text/html',
'Cache-Control': 'no-cache'
}
});
} catch (error) {
logger.error('Failed to read frontend.html:', error);
return new Response('Frontend file not found', { status: 404 });
}
}
// Health check endpoint
if (url.pathname === '/health') {
return new Response(JSON.stringify({
status: 'ok',
frontend: 'serving',
speedtest_server: 'http://localhost:8080'
}), {
headers: { 'Content-Type': 'application/json' }
});
}
return new Response('Not found', { status: 404 });
}
});
logger.info(`Frontend server started on http://localhost:${PORT}`);
logger.info(`Speedtest backend server expected on http://localhost:8080`);
logger.info(`Open http://localhost:${PORT} in your browser to run the speed test`);
process.on('SIGINT', () => {
logger.info('Shutting down frontend server...');
server.stop();
process.exit(0);
});
process.on('SIGTERM', () => {
logger.info('Shutting down frontend server...');
server.stop();
process.exit(0);
});