create-aomex 0.0.67 → 0.0.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-aomex",
3
- "version": "0.0.67",
3
+ "version": "0.0.68",
4
4
  "repository": "git@github.com:aomex/create-aomex.git",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,6 +19,10 @@ const app = new ConsoleApp({
19
19
  ],
20
20
  });
21
21
 
22
+ process.on('uncaughtException', (err) => {
23
+ logger.error(err.stack!);
24
+ });
25
+
22
26
  app.on('error', (err) => {
23
27
  logger.error(err.stack!);
24
28
  });
@@ -8,6 +8,8 @@ import { swagger } from '@middleware/swagger.md';
8
8
  import { slowTrace } from '@middleware/slow-trace.md';
9
9
  import { httpLogger } from '@middleware/http-logger.md';
10
10
  import { logger } from '@services/logger';
11
+ import cluster from 'node:cluster';
12
+ import { cpus } from 'node:os';
11
13
 
12
14
  export const app = new WebApp({
13
15
  language: 'zh_CN',
@@ -24,18 +26,36 @@ export const app = new WebApp({
24
26
  ],
25
27
  });
26
28
 
27
- app.on('error', (err, ctx) => {
29
+ process.on('uncaughtException', (err) => {
28
30
  logger.error(err.stack!);
29
- ctx.response.body = {
30
- status: ctx.response.statusCode,
31
- message: ctx.response.body,
32
- };
33
31
  });
34
32
 
35
- const port = process.env['PORT'] || 3000;
36
- app.listen(port, () => {
37
- console.log(`服务已启动,点击 http://localhost:${port} 访问`);
38
- });
33
+ if (cluster.isWorker) {
34
+ app.on('error', (err, ctx) => {
35
+ logger.error(err.stack!);
36
+ ctx.response.body = {
37
+ status: ctx.response.statusCode,
38
+ message: ctx.response.body,
39
+ };
40
+ });
41
+ app.listen(process.env['PORT'] || 3000);
42
+ }
43
+
44
+ if (cluster.isPrimary) {
45
+ for (let i = cpus().length; i-- > 0; ) {
46
+ cluster.fork();
47
+ }
48
+
49
+ cluster
50
+ .on('listening', (worker, address) => {
51
+ const href = `http://${address.address || 'localhost'}:${address.port}`;
52
+ logger.info(`Worker ${worker.id} is listening ${href}`);
53
+ })
54
+ .on('exit', (worker, code, signal) => {
55
+ logger.error(`Worker ${worker.id} exit with code '${code}' and signal '${signal}'`);
56
+ cluster.fork();
57
+ });
58
+ }
39
59
 
40
60
  declare module '@aomex/web' {
41
61
  namespace WebApp {