diff --git a/back/config/index.ts b/back/config/index.ts index 1274634a..2534ddda 100644 --- a/back/config/index.ts +++ b/back/config/index.ts @@ -3,11 +3,18 @@ import path from 'path'; import { createRandomString } from './util'; process.env.NODE_ENV = process.env.NODE_ENV || 'development'; +// 声明QL_DIR环境变量 +let qlHomePath = path.join(__dirname, '../../'); +// 生产环境 +if (qlHomePath.endsWith('/static/')) { + qlHomePath = path.join(qlHomePath, '../'); +} +process.env.QL_DIR = qlHomePath; const lastVersionFile = `http://qn.whyour.cn/version.ts?v=${Date.now()}`; const envFound = dotenv.config(); -const rootPath = process.cwd(); +const rootPath = qlHomePath; const dataPath = path.join(rootPath, 'data/'); const samplePath = path.join(rootPath, 'sample/'); const configPath = path.join(dataPath, 'config/'); diff --git a/back/loaders/initFile.ts b/back/loaders/initFile.ts index 90899fd9..38a251fe 100644 --- a/back/loaders/initFile.ts +++ b/back/loaders/initFile.ts @@ -5,7 +5,7 @@ import dotenv from 'dotenv'; import Logger from './logger'; import { fileExist } from '../config/util'; -const rootPath = process.cwd(); +const rootPath = process.env.QL_DIR as string;; const dataPath = path.join(rootPath, 'data/'); const configPath = path.join(dataPath, 'config/'); const scriptPath = path.join(dataPath, 'scripts/'); @@ -64,13 +64,5 @@ export default async () => { dotenv.config({ path: confFile }); - // 声明QL_DIR环境变量 - let qlHomePath = path.join(__dirname, '../../'); - // 生产环境 - if (qlHomePath.endsWith('/static/')) { - qlHomePath = path.join(qlHomePath, '../'); - } - process.env.QL_DIR = qlHomePath; - Logger.info('✌️ Init file down'); };