MCPcopy
hub / github.com/stenciljs/core / startServer

Function startServer

test/runtime-benchmark/benchmark-runtime.js:42–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40}
41
42function 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
72const BENCHMARK_LABELS = {
73 create1k: 'Create 1,000 rows',

Callers 1

mainFunction · 0.70

Calls 4

resolveFunction · 0.85
joinMethod · 0.80
extnameMethod · 0.80
readFileMethod · 0.80

Tested by

no test coverage detected