Skip to content

Commit 7c05693

Browse files
RafaelGSSwesleytodd
authored andcommitted
cli: add local-server to expf
1 parent efdafc1 commit 7c05693

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "ExpressJS Performance Working Group",
55
"scripts": {
66
"setup": "npm i",
7+
"local-server": "expf local-server",
78
"test": "echo \"Error: no test specified\" && exit 1",
89
"load": "expf load",
910
"test:load": "expf load --test=@expressjs/perf-load-example",

packages/cli/bin/expf.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ switch (positionals[2]) {
7878
console.error(e);
7979
}
8080
break;
81+
case 'local-server':
82+
try {
83+
await (await import('../local-server.mjs')).default(values);
84+
} catch (e) {
85+
console.error(e);
86+
}
87+
break;
8188
default:
8289
console.log(`
8390
Express Performance Testing CLI

packages/cli/load.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { normalize, join, dirname } from 'node:path';
22
import { writeFile, mkdir } from 'node:fs/promises';
33
import nv from '@pkgjs/nv';
44

5+
// TODO: Add description to each flag
56
export function help (opts = {}) {
67
return `$ expf load [flags]
78

packages/cli/local-server.mjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { join } from 'node:path';
2+
import { spawn } from 'node:child_process';
3+
4+
// TODO: add options to load different servers
5+
export function help () {
6+
return `$ expf local-server
7+
8+
Start Express local HTTP server
9+
`
10+
}
11+
12+
export function startServer () {
13+
const server = spawn(
14+
process.execPath,
15+
[
16+
join(import.meta.dirname, '../../servers/node-http/index.mjs'),
17+
],
18+
{
19+
env: {
20+
...process.env,
21+
PORT: 3000
22+
},
23+
stdio: ['inherit', 'inherit', 'inherit']
24+
}
25+
);
26+
27+
return new Promise((resolve, reject) => {
28+
server.on('error', reject);
29+
server.on('close', resolve);
30+
31+
process.on('beforeExit', () => {
32+
server.close();
33+
});
34+
})
35+
}
36+
37+
export default async function main (_opts = {}) {
38+
await startServer();
39+
}

0 commit comments

Comments
 (0)