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 +1 -1
- package/templates/src/cli.ts +4 -0
- package/templates/src/web.ts +29 -9
package/package.json
CHANGED
package/templates/src/cli.ts
CHANGED
package/templates/src/web.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
36
|
-
app.
|
|
37
|
-
|
|
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 {
|