-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (21 loc) · 887 Bytes
/
server.js
File metadata and controls
27 lines (21 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const http = require('node:http');
const path = require('node:path');
const mock = require('egg-mock');
const appName = process.argv[2];
const app = mock.app({
baseDir: path.join(__dirname, appName),
framework: path.join(__dirname, '../..'),
});
app.ready().then(() => {
console.log('app(%s) ready', app.config.baseDir);
const server = http.createServer(app.callback());
// emit server event just like egg-cluster
// https://github.com/eggjs/egg-cluster/blob/master/lib/app_worker.js#L52
app.emit('server', server);
server.listen(7001, () => {
console.log('Server started at 7001');
});
});
// see https://www.smashingmagazine.com/2018/06/nodejs-tools-techniques-performance-servers/
// $ clinic doctor --on-port 'autocannon http://localhost:7001' -- node server.js hello
// $ clinic flame --on-port 'autocannon http://localhost:7001' -- node server.js hello