mirror of
https://github.com/certd/certd.git
synced 2026-05-16 05:07:32 +08:00
perf: 自动生成jwtkey,无需手动配置
This commit is contained in:
@@ -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