Skip to content

Commit 5715d96

Browse files
committed
feat: Add rescue guide download feature
1 parent 06e87f9 commit 5715d96

21 files changed

Lines changed: 411 additions & 210 deletions

File tree

apps/backend/auth-service/src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { AppModule } from './app.module';
77

88
async function bootstrap(): Promise<void> {
99
const logger = new Logger('Bootstrap');
10-
const app = await NestFactory.create<NestExpressApplication>(AppModule);
10+
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
11+
bufferLogs: true,
12+
});
1113
const configService = app.get(ConfigService) as ConfigService;
1214
app.setGlobalPrefix(configService.get('http.prefix')!);
1315
const port = configService.get('http.port');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DOCUMENT_SERVICE_MONGODB=your-mongodb-url

apps/backend/document-service/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"name": "@pawhaven/document-service",
44
"version": "1.0.0",
55
"scripts": {
6-
"postinstall": "pnpm run prisma:generate-mongodb",
76
"dev": "nest start --watch",
87
"build": "nest build",
9-
"install:core-service": "pnpm --filter=@pawhaven/document-service... install",
8+
"install:document-service": "pnpm --filter=@pawhaven/document-service... install",
109
"turbo:build": "turbo run build --filter=@pawhaven/document-service --env-mode=loose",
1110
"start": "node dist/main.js",
1211
"typecheck": "tsc --noEmit"
1312
},
1413
"dependencies": {
14+
"@pawhaven/backend-core": "workspace:*",
1515
"@nestjs-modules/mailer": "^2.0.2",
1616
"@nestjs/axios": "^4.0.1",
1717
"@nestjs/common": "^11.1.6",
Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
import path from 'node:path'
2-
import { Module } from '@nestjs/common'
3-
import SharedModule from '@shared/shared.module'
4-
import EmailModule from './modules/Email/email.module'
5-
import PDFModule from './modules/PDF/PDF.module'
6-
import { EnvConstant } from '@shared/constants/constant'
7-
import FileModule from '@modules/File/file.module'
8-
const currentEnv = process.env.NODE_ENV ?? 'uat'
9-
const configFilePath = path.resolve(__dirname, `./config/${EnvConstant[currentEnv]}/env/index.yaml`)
1+
import { Module } from '@nestjs/common';
2+
import { FileModule } from '@modules/File/file.module';
3+
import {
4+
microServiceNames,
5+
SharedModule,
6+
SharedModuleFeatures,
7+
} from '@pawhaven/backend-core';
8+
import { EmailModule } from '@modules/Email/email.module';
9+
import { PDFModule } from '@modules/PDF/PDF.module';
10+
1011
@Module({
11-
imports: [
12-
SharedModule.forRoot({
13-
configFilePath
14-
}),
15-
EmailModule,
16-
PDFModule,
17-
FileModule
18-
],
19-
providers: []
12+
imports: [
13+
SharedModule.forRoot({
14+
serviceName: microServiceNames.DOCUMENT,
15+
modules: [
16+
{
17+
module: SharedModuleFeatures.SwaggerModule,
18+
},
19+
],
20+
}),
21+
EmailModule,
22+
PDFModule,
23+
FileModule,
24+
],
25+
providers: [],
2026
})
2127
export class AppModule {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
http:
2+
env: dev
3+
port: 8083
4+
prefix: document-service
5+
timeout: 5000
6+
retryCount: 3
7+
retryDelay: 500
8+
9+
swagger:
10+
title: 管理后台
11+
version: 1.0
12+
prefix: api-docs
13+
description: 管理后台接口文档
14+
15+
dbConnections:
16+
- enable: true
17+
options:
18+
name: DOCUMENT_SERVICE_DB
19+
uri: ${DOCUMENT_SERVICE_DB}
20+
21+
cors:
22+
allowedHeaders:
23+
- X-timestamp
24+
- Access-Token
25+
- Accept
26+
- Content-Type
27+
- X-Sign
28+
- x-locale
29+
- Locale
30+
origin:
31+
- http://localhost:3001
32+
credentials: true
33+
optionsSuccessStatus: 204
34+
methods:
35+
- GET
36+
- POST
37+
- PUT
38+
- DELETE
39+
- PATCH
40+
- OPTIONS
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
http:
2+
env: prod
3+
port: 8083
4+
prefix: document-service
5+
timeout: 5000
6+
retryCount: 3
7+
retryDelay: 500
8+
9+
swagger:
10+
title: 管理后台
11+
version: 1.0
12+
prefix: api-docs
13+
description: 管理后台接口文档
14+
15+
DBConnections:
16+
- enable: true
17+
options:
18+
name: DOCUMENT_SERVICE_DB
19+
uri: ${DOCUMENT_SERVICE_DB}
20+
21+
cors:
22+
allowedHeaders:
23+
- X-timestamp
24+
- Access-Token
25+
- Accept
26+
- Content-Type
27+
- X-Sign
28+
- x-locale
29+
- Locale
30+
origin:
31+
- https://pawhaven.work
32+
credentials: true
33+
optionsSuccessStatus: 204
34+
methods:
35+
- GET
36+
- POST
37+
- PUT
38+
- DELETE
39+
- PATCH
40+
- OPTIONS
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
http:
2+
env: test
3+
port: 8083
4+
prefix: document-service
5+
timeout: 5000
6+
retryCount: 3
7+
retryDelay: 500
8+
9+
swagger:
10+
title: 管理后台
11+
version: 1.0
12+
prefix: api-docs
13+
description: 管理后台接口文档
14+
15+
DBConnections:
16+
- enable: true
17+
options:
18+
name: DOCUMENT_SERVICE_DB
19+
uri: ${DOCUMENT_SERVICE_DB}
20+
21+
cors:
22+
allowedHeaders:
23+
- X-timestamp
24+
- Access-Token
25+
- Accept
26+
- Content-Type
27+
- X-Sign
28+
- x-locale
29+
- Locale
30+
origin:
31+
- http://localhost:3001
32+
credentials: true
33+
optionsSuccessStatus: 204
34+
methods:
35+
- GET
36+
- POST
37+
- PUT
38+
- DELETE
39+
- PATCH
40+
- OPTIONS
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# github action 中如何登录 azure
2+
3+
1. 先到 App registrations 注册 app 获取 appid 和 tenantId, 一定要记住 secret value
4+
2. 绑定权限 az role assignment create \
5+
--assignee <appId> \
6+
--role Contributor \
7+
--scope /subscriptions/<subscription-id>
8+
9+
{
10+
"clientId": "**\*\***\***\*\***",
11+
"clientSecret": "\***\*\*\*\*\*\*\***",
12+
"subscriptionId": "**\*\***\***\*\***",
13+
"tenantId": "**\*\***\***\*\***"
14+
}
15+
16+
3. 将获取的内容绑定到 github action 中
17+
18+
# API 端口如何设置
19+
20+
1. 具体 app 中会监听特定端口,如 3000
21+
2. app 中监听的 host 必须为 0.0.0.0
22+
3. service 的 targetPort 必须保持和 app 中监听的端口一致
23+
24+
# AKS 如何设置 gateway
25+
26+
1. 注册 nginx
27+
在 azure port command 中运行
28+
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.9.4/deploy/static/provider/cloud/deploy.yaml
29+
2. 部署 ingress nginx 到 aks , 参考 aksSettings 中的 proxy
30+
31+
# 微服务之间相互调用出现无法 call 通
32+
33+
记住微服务之间通过端口号 call,必须在 deploy 和 service 中详细写明端口号的映射
34+
35+
例如
36+
37+
service:
38+
ports: - protocol: TCP
39+
port: 8083
40+
targetPort: 8083
41+
42+
deploy:
43+
44+
ports: - containerPort: 8083
45+
46+
# 微服务调用一直 pening
47+
48+
- 确定监听的 host 必须为 0.0.0.0
49+
- 微服务的 clusterIP 地址不需要加前缀 http 或者 https
50+
- deploy 和 service 的端口必须和实际运行的端口保持一致!!!
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
http:
2+
env: uat
3+
port: 8083
4+
prefix: document-service
5+
timeout: 5000
6+
retryCount: 3
7+
retryDelay: 500
8+
9+
swagger:
10+
title: 管理后台
11+
version: 1.0
12+
prefix: api-docs
13+
description: 管理后台接口文档
14+
15+
DBConnections:
16+
- enable: true
17+
options:
18+
name: DOCUMENT_SERVICE_DB
19+
uri: ${DOCUMENT_SERVICE_DB}
20+
21+
cors:
22+
allowedHeaders:
23+
- X-timestamp
24+
- Access-Token
25+
- Accept
26+
- Content-Type
27+
- X-Sign
28+
- x-locale
29+
- Locale
30+
origin:
31+
- http://localhost:3001
32+
credentials: true
33+
optionsSuccessStatus: 204
34+
methods:
35+
- GET
36+
- POST
37+
- PUT
38+
- DELETE
39+
- PATCH
40+
- OPTIONS
Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,28 @@
1-
import { ValidationPipe, VersioningType } from '@nestjs/common'
2-
import { ConfigService } from '@nestjs/config'
3-
import { NestFactory } from '@nestjs/core'
4-
import { NestExpressApplication } from '@nestjs/platform-express'
5-
import helmet from 'helmet'
6-
import i18n from 'i18n'
1+
import type { NestExpressApplication } from '@nestjs/platform-express';
2+
import { NestFactory } from '@nestjs/core';
3+
import { ConfigService } from '@nestjs/config';
4+
import { Logger } from '@nestjs/common';
75

8-
import { AppModule } from './app.module'
6+
import { AppModule } from './app.module';
97

10-
async function bootstrap() {
11-
// Hybrid application
12-
// can be used as a microservice or a web service both
8+
async function bootstrap(): Promise<void> {
9+
const logger = new Logger('Bootstrap');
1310
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
14-
bufferLogs: true
15-
})
16-
17-
// Initialize i18n
18-
app.use(i18n.init)
19-
20-
// global service prefix
21-
const prefix = app.get(ConfigService).get('http.prefix') ?? ''
22-
app.setGlobalPrefix(prefix)
23-
24-
// Version control like v1 v2
25-
app.enableVersioning({
26-
type: VersioningType.URI
27-
})
28-
29-
// DTO pipe settings
30-
app.useGlobalPipes(
31-
new ValidationPipe({
32-
transform: true,
33-
whitelist: true
34-
})
35-
)
36-
37-
// avoid attack
38-
app.use(helmet())
39-
40-
const port = app.get(ConfigService).get('http.port') ?? 8082
41-
// As a web service
42-
await app
43-
.listen(port, '0.0.0.0')
44-
.catch((error) => {
45-
console.error(`MS_Document start error:${error}`)
46-
})
11+
bufferLogs: true,
12+
});
13+
const configService = app.get(ConfigService) as ConfigService;
14+
app.setGlobalPrefix(configService.get('http.prefix')!);
15+
const port = configService.get('http.port');
16+
17+
try {
18+
await app.listen(port, '0.0.0.0');
19+
logger.log(`document-service running at http://localhost:${port}`);
20+
} catch (error) {
21+
logger.error('Failed to start document-service', error);
22+
throw new Error(
23+
`Bootstrap failed: ${error instanceof Error ? error.message : error}`,
24+
);
25+
}
4726
}
48-
bootstrap()
27+
28+
bootstrap();

0 commit comments

Comments
 (0)