create-aomex 0.0.67 → 0.0.69
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/.env +1 -1
- package/templates/Dockerfile.integration +1 -2
- package/templates/Dockerfile.production +1 -2
- package/templates/docker-compose.yml +1 -3
- package/templates/src/cli.ts +4 -0
- package/templates/src/routers/{hello.router.ts → index.router.ts} +3 -6
- package/templates/src/web.ts +30 -9
- package/templates/tsconfig.json +2 -3
package/package.json
CHANGED
package/templates/.env
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
DATABASE_URL=mysql://
|
|
1
|
+
DATABASE_URL=mysql://root:abcde@localhost:3306/{{projectName}}
|
|
@@ -7,9 +7,8 @@ RUN mv .env.integration .env
|
|
|
7
7
|
ENV TZ=Asia/Shanghai
|
|
8
8
|
ENV PORT=3000
|
|
9
9
|
ENV NODE_ENV=integration
|
|
10
|
-
ENV NODE_OPTIONS='--enable-source-maps --stack-trace-limit=50'
|
|
11
10
|
ENV PATH="$PATH:/codes/node_modules/.bin"
|
|
12
11
|
|
|
13
12
|
RUN sh scripts/build-in-docker.sh
|
|
14
13
|
|
|
15
|
-
CMD ["node", "src/web.js"]
|
|
14
|
+
CMD ["node", "--enable-source-maps", "--stack-trace-limit=50", "src/web.js"]
|
|
@@ -7,9 +7,8 @@ RUN mv .env.production .env
|
|
|
7
7
|
ENV TZ=Asia/Shanghai
|
|
8
8
|
ENV PORT=3000
|
|
9
9
|
ENV NODE_ENV=production
|
|
10
|
-
ENV NODE_OPTIONS='--enable-source-maps --stack-trace-limit=50'
|
|
11
10
|
ENV PATH="$PATH:/codes/node_modules/.bin"
|
|
12
11
|
|
|
13
12
|
RUN sh scripts/build-in-docker.sh
|
|
14
13
|
|
|
15
|
-
CMD ["node", "src/web.js"]
|
|
14
|
+
CMD ["node", "--enable-source-maps", "--stack-trace-limit=50", "src/web.js"]
|
|
@@ -5,8 +5,6 @@ services:
|
|
|
5
5
|
MYSQL_ROOT_PASSWORD: 'abcde'
|
|
6
6
|
# 修改后需要同步修改.env里的参数
|
|
7
7
|
MYSQL_DATABASE: '{{projectName}}'
|
|
8
|
-
MYSQL_USER: 'my_user'
|
|
9
|
-
MYSQL_PASSWORD: 'my_pwd'
|
|
10
8
|
volumes:
|
|
11
9
|
- ./volumes/mysql:/var/lib/mysql
|
|
12
10
|
ports:
|
|
@@ -19,7 +17,7 @@ services:
|
|
|
19
17
|
timeout: 3s
|
|
20
18
|
retries: 10
|
|
21
19
|
redis:
|
|
22
|
-
image: redis:8.0
|
|
20
|
+
image: redis:8.0
|
|
23
21
|
volumes:
|
|
24
22
|
- ./volumes/redis:/data
|
|
25
23
|
ports:
|
package/templates/src/cli.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { rule } from '@aomex/common';
|
|
2
|
-
import {
|
|
2
|
+
import { response, Router } from '@aomex/web';
|
|
3
3
|
|
|
4
4
|
export const router = new Router();
|
|
5
5
|
|
|
6
6
|
router.get('/', {
|
|
7
|
+
docs: { showInOpenapi: false },
|
|
7
8
|
mount: [
|
|
8
|
-
query({
|
|
9
|
-
user: rule.string().optional(),
|
|
10
|
-
}),
|
|
11
9
|
response({
|
|
12
10
|
statusCode: 200,
|
|
13
11
|
content: rule.string(),
|
|
14
12
|
}),
|
|
15
13
|
],
|
|
16
14
|
action: (ctx) => {
|
|
17
|
-
|
|
18
|
-
ctx.send(`Hello ${user}`);
|
|
15
|
+
ctx.send('Hello World');
|
|
19
16
|
},
|
|
20
17
|
});
|
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,37 @@ 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
|
+
const msg = `Worker ${worker.id} exit with code '${code}' and signal '${signal}'`;
|
|
56
|
+
logger.error(msg);
|
|
57
|
+
cluster.fork();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
39
60
|
|
|
40
61
|
declare module '@aomex/web' {
|
|
41
62
|
namespace WebApp {
|