mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
修改服务启动逻辑
This commit is contained in:
+53
-13
@@ -2,12 +2,60 @@ import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
import { createRandomString } from './share';
|
||||
|
||||
dotenv.config({
|
||||
path: path.join(__dirname, '../../.env'),
|
||||
});
|
||||
|
||||
interface Config {
|
||||
port: number;
|
||||
grpcPort: number;
|
||||
nodeEnv: string;
|
||||
isDevelopment: boolean;
|
||||
isProduction: boolean;
|
||||
jwt: {
|
||||
secret: string;
|
||||
expiresIn?: string;
|
||||
};
|
||||
cors: {
|
||||
origin: string[];
|
||||
methods: string[];
|
||||
};
|
||||
logs: {
|
||||
level: string;
|
||||
};
|
||||
api: {
|
||||
prefix: string;
|
||||
};
|
||||
}
|
||||
|
||||
const config: Config = {
|
||||
port: parseInt(process.env.BACK_PORT || '5600', 10),
|
||||
grpcPort: parseInt(process.env.GRPC_PORT || '5500', 10),
|
||||
nodeEnv: process.env.NODE_ENV || 'development',
|
||||
isDevelopment: process.env.NODE_ENV === 'development',
|
||||
isProduction: process.env.NODE_ENV === 'production',
|
||||
logs: {
|
||||
level: process.env.LOG_LEVEL || 'silly',
|
||||
},
|
||||
api: {
|
||||
prefix: '/api',
|
||||
},
|
||||
jwt: {
|
||||
secret: process.env.JWT_SECRET || createRandomString(16, 32),
|
||||
expiresIn: process.env.JWT_EXPIRES_IN,
|
||||
},
|
||||
cors: {
|
||||
origin: process.env.CORS_ORIGIN
|
||||
? process.env.CORS_ORIGIN.split(',')
|
||||
: ['*'],
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
},
|
||||
};
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
if (!process.env.QL_DIR) {
|
||||
// 声明QL_DIR环境变量
|
||||
let qlHomePath = path.join(__dirname, '../../');
|
||||
// 生产环境
|
||||
if (qlHomePath.endsWith('/static/')) {
|
||||
qlHomePath = path.join(qlHomePath, '../');
|
||||
}
|
||||
@@ -65,17 +113,8 @@ if (envFound.error) {
|
||||
}
|
||||
|
||||
export default {
|
||||
port: parseInt(process.env.BACK_PORT as string, 10),
|
||||
cronPort: parseInt(process.env.CRON_PORT as string, 10),
|
||||
publicPort: parseInt(process.env.PUBLIC_PORT as string, 10),
|
||||
updatePort: parseInt(process.env.UPDATE_PORT as string, 10),
|
||||
secret: process.env.SECRET || createRandomString(16, 32),
|
||||
logs: {
|
||||
level: process.env.LOG_LEVEL || 'silly',
|
||||
},
|
||||
api: {
|
||||
prefix: '/api',
|
||||
},
|
||||
...config,
|
||||
jwt: config.jwt,
|
||||
rootPath,
|
||||
tmpPath,
|
||||
dataPath,
|
||||
@@ -118,6 +157,7 @@ export default {
|
||||
bakPath,
|
||||
apiWhiteList: [
|
||||
'/api/user/login',
|
||||
'/api/health',
|
||||
'/open/auth/token',
|
||||
'/api/user/two-factor/login',
|
||||
'/api/system',
|
||||
|
||||
Reference in New Issue
Block a user