From 2902d637027c94baef19100fe87577e3d15cd133 Mon Sep 17 00:00:00 2001 From: luoer <952222@163.com> Date: Wed, 18 Oct 2023 17:53:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96swagger=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/stack.yaml | 40 +++++++++++++++++++++++++++++++++ src/common/swagger/util.ts | 40 ++++++++++++++++++++++++--------- src/config/config.service.ts | 35 +++++++++++++++++++++++++++++ src/database/database.module.ts | 11 +++++++++ 4 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 .gitea/stack.yaml diff --git a/.gitea/stack.yaml b/.gitea/stack.yaml new file mode 100644 index 0000000..5e2ce65 --- /dev/null +++ b/.gitea/stack.yaml @@ -0,0 +1,40 @@ +version: '3' + +services: + server: + image: git.dev.juetan.cn/juetan/server:latest + networks: + - public + deploy: + mode: replicated + replicas: 1 + placement: + constraints: [node.role == manager] + labels: + - traefik.enable=true + - traefik.http.routers.nest.rule=Host(`nest.dev.juetan.cn`) && PathPrefix(`/api`, `/upload`) + - traefik.http.routers.nest.entrypoints=websecure + - traefik.http.routers.nest.tls=true + - traefik.http.routers.nest.tls.certresolver=acmer + - traefik.http.services.nest1.loadbalancer.server.port=3030 + + web: + image: git.dev.juetan.cn/juetan/web:latest + networks: + - public + deploy: + mode: replicated + replicas: 1 + placement: + constraints: [node.role == manager] + labels: + - traefik.enable=true + - traefik.http.routers.vue.rule=Host(`nest.dev.juetan.cn`) + - traefik.http.routers.vue.entrypoints=websecure + - traefik.http.routers.vue.tls=true + - traefik.http.routers.vue.tls.certresolver=acmer + - traefik.http.services.vue1.loadbalancer.server.port=80 + +networks: + public: + external: true \ No newline at end of file diff --git a/src/common/swagger/util.ts b/src/common/swagger/util.ts index 6fd2990..e8653ce 100644 --- a/src/common/swagger/util.ts +++ b/src/common/swagger/util.ts @@ -37,20 +37,38 @@ export function addResponseWrapper(doc: OpenAPIObject) { continue; } const schema = json.schema; + // json.schema = { + // allOf: [ + // { + // $ref: '#/components/schemas/Response', + // }, + // { + // type: 'object', + // properties: { + // data: schema, + // }, + // required: ['data'], + // }, + // ], + // }; json.schema = { - allOf: [ - { - $ref: '#/components/schemas/Response', + type: 'object', + properties: { + code: { + type: 'integer', + description: '状态码', + example: 2000, + format: 'int32', }, - { - type: 'object', - properties: { - data: schema, - }, - required: ['data'], + message: { + type: 'string', + description: '提示信息', + example: '请求成功', }, - ], - }; + data: schema, + }, + required: ['code', 'message'], + } } } } diff --git a/src/config/config.service.ts b/src/config/config.service.ts index a212a20..7517841 100644 --- a/src/config/config.service.ts +++ b/src/config/config.service.ts @@ -90,6 +90,41 @@ export class ConfigService { return this.config.get('DB_TYPE', 'sqlite'); } + /** + * MySQL数据库主机 + */ + get sqlHost(): string { + return this.config.get('DB_MYSQL_HOST', 'localhost'); + } + + /** + * MySQL数据库端口 + */ + get sqlPort(): number { + return Number(this.config.get('DB_MYSQL_PORT', 3306)); + } + + /** + * MySQL数据库用户 + */ + get sqlUser(): string { + return this.config.get('DB_MYSQL_USERNAME', 'root'); + } + + /** + * MySQL数据库密码 + */ + get sqlPass(): string { + return this.config.get('DB_MYSQL_PASSWORD', ''); + } + + /** + * MySQL数据库名称 + */ + get sqlDatabase(): string { + return this.config.get('DB_MYSQL_DATABASE', 'appnify'); + } + /** * SQLite数据库文件路径 * @default './content/db.sqlite' diff --git a/src/database/database.module.ts b/src/database/database.module.ts index 01bc2f4..4963be9 100644 --- a/src/database/database.module.ts +++ b/src/database/database.module.ts @@ -23,6 +23,17 @@ import { RequestMiddleware } from './suscribers/request.middleware'; }; } if (config.dbType === 'mysql') { + return { + type: config.dbType, + host: config.sqlHost, + port: config.sqlPort, + username: config.sqlUser, + password: config.sqlPass, + database: config.sqlDatabase, + synchronize: true, + autoLoadEntities: true, + namingStrategy: new SnakeNamingStrategy(), + }; } }, inject: [ConfigService],