修改项目启动
This commit is contained in:
parent
5983298f2e
commit
bfc937c585
|
@ -4,5 +4,5 @@ TEST_VALUE:
|
|||
DATABASE: drive
|
||||
USER: root
|
||||
PORT: 3306
|
||||
HOST: localhost
|
||||
HOST: 127.0.0.1
|
||||
PASSWORD: zhonglian405
|
|
@ -4,5 +4,5 @@ TEST_VALUE:
|
|||
DATABASE: drive
|
||||
USER: root
|
||||
PORT: 3306
|
||||
HOST: localhost
|
||||
HOST: 127.0.0.1
|
||||
PASSWORD: zhonglian405
|
|
@ -21,7 +21,7 @@
|
|||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^10.0.5",
|
||||
"@nestjs/common": "^10.3.1",
|
||||
"@nestjs/config": "^3.0.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/mapped-types": "*",
|
||||
|
@ -29,7 +29,7 @@
|
|||
"@nestjs/platform-fastify": "^10.0.4",
|
||||
"@nestjs/platform-socket.io": "^10.3.0",
|
||||
"@nestjs/serve-static": "^4.0.0",
|
||||
"@nestjs/typeorm": "^10.0.0",
|
||||
"@nestjs/typeorm": "^10.0.1",
|
||||
"@nestjs/websockets": "^10.3.0",
|
||||
"axios": "^1.4.0",
|
||||
"chalk": "^3.0.0",
|
||||
|
|
|
@ -4,6 +4,7 @@ import { AppService } from './app.service';
|
|||
import { ClientModule } from './client/client.module';
|
||||
import { GatewayModule } from './gateway/gateway.module';
|
||||
import { TypeOrmModule, TypeOrmModuleAsyncOptions } from '@nestjs/typeorm';
|
||||
import { getMysql } from './utils/config';
|
||||
// import 'winston-daily-rotate-file';
|
||||
|
||||
@Module({
|
||||
|
@ -11,23 +12,7 @@ import { TypeOrmModule, TypeOrmModuleAsyncOptions } from '@nestjs/typeorm';
|
|||
// 加载连接数据库
|
||||
TypeOrmModule.forRootAsync({
|
||||
useFactory: async () => {
|
||||
return {
|
||||
// type: 'mysql',
|
||||
// host: getConfig().HOST,
|
||||
// port: getConfig().PORT,
|
||||
// username: getConfig().USER,
|
||||
// password: getConfig().PASSWORD,
|
||||
// database: getConfig().DATABASE,
|
||||
type: 'mysql',
|
||||
host: '192.168.10.13',
|
||||
port: 3306,
|
||||
username: 'root',
|
||||
password: '123456',
|
||||
database: 'drive',
|
||||
entities: [__dirname + '/**/*.entity{.ts,.js}'], // 扫描本项目中.entity.ts或者.entity.js的文件
|
||||
synchronize: false,
|
||||
logging: true,
|
||||
} as TypeOrmModuleAsyncOptions;
|
||||
return getMysql() as TypeOrmModuleAsyncOptions;
|
||||
},
|
||||
}),
|
||||
ClientModule,
|
||||
|
|
|
@ -1,23 +1,61 @@
|
|||
// /* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// import { parse } from 'yaml';
|
||||
// // import path from 'path';
|
||||
// // import fs from 'fs';
|
||||
// const path = require('path');
|
||||
// const fs = require('fs');
|
||||
import { parse } from 'yaml';
|
||||
// import path from 'path';
|
||||
// import fs from 'fs';
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// // 获取项目运行环境
|
||||
// export const getEnv = () => {
|
||||
// // console.log(process.env);
|
||||
// return process.env.RUNNING_ENV || 'prod';
|
||||
// };
|
||||
// 获取项目运行环境
|
||||
export const getEnv = () => {
|
||||
// console.log(process.env);
|
||||
return process.env.RUNNING_ENV || 'prod';
|
||||
};
|
||||
|
||||
// // 读取项目配置
|
||||
// export const getConfig = () => {
|
||||
// const environment = getEnv();
|
||||
// const yamlPath = path.join(process.cwd(), `./.config/.${environment}.yaml`);
|
||||
// const file = fs.readFileSync(yamlPath, 'utf8');
|
||||
// let config = parse(file);
|
||||
// // 融合注入参数
|
||||
// config = Object.assign(config, process.env);
|
||||
// return config;
|
||||
// };
|
||||
let configAll = { isExist: false }
|
||||
// 读取项目配置
|
||||
export const getConfig = () => {
|
||||
if (configAll.isExist) {
|
||||
return configAll
|
||||
}
|
||||
const environment = getEnv();
|
||||
const yamlPath = path.join(process.cwd(), `./.config/.${environment}.yaml`);
|
||||
const file = fs.readFileSync(yamlPath, 'utf8');
|
||||
let config = parse(file);
|
||||
if (process?.argv[2]?.length) {
|
||||
config = { ...config, HOST: process.argv[2] }
|
||||
}
|
||||
if (process?.argv[3]?.length) {
|
||||
config = { ...config, USER: process.argv[3] }
|
||||
}
|
||||
if (process?.argv[4]?.length) {
|
||||
config = { ...config, PASSWORD: process.argv[4] }
|
||||
}
|
||||
// 融合注入参数
|
||||
// config = Object.assign(config, process.env);
|
||||
console.log(config)
|
||||
configAll = { ...config, isExist: true }
|
||||
return config;
|
||||
};
|
||||
|
||||
export const getMysql = () => {
|
||||
const mysql = {
|
||||
type: 'mysql',
|
||||
host: getConfig().HOST,
|
||||
port: getConfig().PORT,
|
||||
username: getConfig().USER,
|
||||
password: getConfig().PASSWORD,
|
||||
database: getConfig().DATABASE,
|
||||
// type: 'mysql',
|
||||
// host: '192.168.10.13',
|
||||
// port: 3306,
|
||||
// username: 'root',
|
||||
// password: '123456',
|
||||
// database: 'drive',
|
||||
entities: [__dirname + '/**/*.entity{.ts,.js}'], // 扫描本项目中.entity.ts或者.entity.js的文件
|
||||
synchronize: false,
|
||||
logging: true,
|
||||
}
|
||||
console.log(mysql);
|
||||
|
||||
return mysql
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user