* 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
3.0 KiB
3.0 KiB
Speedtest Application
A full-stack network speed testing application built with Bun.js.
Architecture
- Server: Single Bun.js HTTP server serving both frontend and APIs
- Frontend: HTML/JavaScript client served at
/for running speed tests - Configuration: Maximum request body size set to 3GB for large file uploads
- APIs:
GET /- Speedtest frontend UIGET /_health/readiness- Health checkGET /data?size=<bytes>- Download random test dataPOST /data?requestId=<id>- Upload data for validation
Quick Start
1. Start the Server
bun run start
Server will start on http://localhost:8080 with both backend APIs and frontend served from the same server.
2. Run Speed Test
- Open
http://localhost:8080in your browser - Select test size (1MB - 50MB)
- Click "Start Speed Test"
- View download/upload speeds and validation results
Development
Run Both Servers Simultaneously
# Requires concurrently (npm install -D concurrently)
bun run dev
Manual Testing
Test the API directly:
# Health check
curl http://localhost:8080/_health/readiness
# Download test (1MB)
curl -o test.dat http://localhost:8080/data?size=1048576
# Upload same data back (get requestId from previous response headers)
curl -X POST "http://localhost:8080/data?requestId=<request-id>" \
--data-binary @test.dat \
-H "Content-Type: application/octet-stream"
Speed Test Workflow
- Download Phase: Frontend downloads random data from server
- Upload Phase: Frontend uploads the same data back for validation
- Validation: Server verifies data integrity and measures performance
- Results: Frontend displays download/upload speeds, total time, and data integrity status
Features
- ✅ Configurable test sizes (1MB - 2.5GB)
- ✅ Large file support (up to 3GB request body limit)
- ✅ Real-time progress indicators
- ✅ Data integrity validation with SHA256
- ✅ Upload/download speed measurements
- ✅ Clean, responsive UI
- ✅ Comprehensive logging
- ✅ Error handling and recovery
API Reference
GET /data
Downloads random test data for speed testing.
Query Parameters:
size(number): Size in bytes (default: 10MB)
Response Headers:
Content-Type:application/octet-streamContent-Length: Data sizeContent-Hash: SHA256 hashX-Request-ID: Unique request identifier
POST /data
Uploads data for validation and performance measurement.
Query Parameters:
requestId(string): Request ID from download phase
Response:
{
"requestId": "uuid",
"valid": true,
"expectedHash": "sha256...",
"receivedHash": "sha256...",
"size": 1048576,
"totalTimeMs": 1250,
"dataRateBps": 838860.8,
"dataRateMbps": 6.71,
"timestamp": "2024-01-01T12:00:00.000Z"
}
GET /_health/readiness
Health check endpoint.
Response:
{
"status": "ok",
"timestamp": "2024-01-01T12:00:00.000Z",
"uptime": 123.45,
"memory": {...},
"cpu": [...],
"os": "darwin"
}