mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
perf: 自动生成jwtkey,无需手动配置
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { MidwayConfig } from '@midwayjs/core';
|
||||
import { join } from 'path';
|
||||
import { dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
// const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
// import { join } from 'path';
|
||||
// import { dirname } from 'node:path';
|
||||
// import { fileURLToPath } from 'node:url';
|
||||
// // const __filename = fileURLToPath(import.meta.url);
|
||||
// const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
import { FlywayHistory } from '@certd/midway-flyway-js';
|
||||
import { UserEntity } from '../modules/authority/entity/user.js';
|
||||
@@ -11,8 +11,11 @@ import { PipelineEntity } from '../modules/pipeline/entity/pipeline.js';
|
||||
//import { logger } from '../utils/logger';
|
||||
// load .env file in process.cwd
|
||||
import { mergeConfig } from './loader.js';
|
||||
import { Keys } from './keys.js';
|
||||
|
||||
const keys = Keys.load();
|
||||
const development = {
|
||||
keys: '111',
|
||||
keys: keys.cookieKeys,
|
||||
koa: {
|
||||
port: 7001,
|
||||
},
|
||||
@@ -49,7 +52,7 @@ const development = {
|
||||
* 单数据库实例
|
||||
*/
|
||||
type: 'sqlite',
|
||||
database: join(__dirname, '../../data/db.sqlite'),
|
||||
database: './data/db.sqlite',
|
||||
synchronize: false, // 如果第一次使用,不存在表,有同步的需求可以写 true
|
||||
logging: true,
|
||||
|
||||
@@ -62,17 +65,17 @@ const development = {
|
||||
* 自动升级数据库脚本
|
||||
*/
|
||||
flyway: {
|
||||
scriptDir: join(__dirname, '../../db/migration'),
|
||||
scriptDir: './db/migration',
|
||||
},
|
||||
|
||||
auth: {
|
||||
jwt: {
|
||||
secret: 'certd666',
|
||||
secret: keys.jwtKey,
|
||||
expire: 7 * 24 * 60 * 60, //单位秒
|
||||
},
|
||||
},
|
||||
certd: {
|
||||
fileRootDir: '/app/data/files',
|
||||
fileRootDir: './data/files',
|
||||
},
|
||||
system: {
|
||||
resetAdminPasswd: false,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import fs from 'fs';
|
||||
import yaml from 'js-yaml';
|
||||
import * as _ from 'lodash-es';
|
||||
import { nanoid } from 'nanoid';
|
||||
const KEYS_FILE = './data/keys.yaml';
|
||||
export class Keys {
|
||||
jwtKey: string = nanoid();
|
||||
cookieKeys: string[] = [nanoid()];
|
||||
|
||||
static load(): Keys {
|
||||
const keys = new Keys();
|
||||
if (fs.existsSync(KEYS_FILE)) {
|
||||
const content = fs.readFileSync(KEYS_FILE, 'utf8');
|
||||
const json = yaml.load(content);
|
||||
_.merge(keys, json);
|
||||
}
|
||||
keys.save();
|
||||
return keys;
|
||||
}
|
||||
|
||||
save() {
|
||||
fs.writeFileSync(KEYS_FILE, yaml.dump(this));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user