#!/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); });