| 40 | } |
| 41 | |
| 42 | function startServer() { |
| 43 | return new Promise((resolve) => { |
| 44 | const server = http.createServer((req, res) => { |
| 45 | let filePath = path.join(WWW_DIR, req.url === '/' ? 'index.html' : req.url); |
| 46 | const ext = path.extname(filePath); |
| 47 | const contentTypes = { |
| 48 | '.html': 'text/html', |
| 49 | '.js': 'application/javascript', |
| 50 | '.css': 'text/css', |
| 51 | }; |
| 52 | |
| 53 | fs.readFile(filePath, (err, content) => { |
| 54 | if (err) { |
| 55 | res.writeHead(404); |
| 56 | res.end('Not found'); |
| 57 | } else { |
| 58 | res.writeHead(200, { 'Content-Type': contentTypes[ext] || 'text/plain' }); |
| 59 | res.end(content); |
| 60 | } |
| 61 | }); |
| 62 | }); |
| 63 | |
| 64 | server.listen(0, '127.0.0.1', () => { |
| 65 | const port = server.address().port; |
| 66 | console.log(`Server running on port ${port}`); |
| 67 | resolve({ server, port }); |
| 68 | }); |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | const BENCHMARK_LABELS = { |
| 73 | create1k: 'Create 1,000 rows', |