chore: optimize environmental variables (#3528)

This commit is contained in:
chenos 2024-02-20 10:35:24 +08:00 committed by GitHub
parent 041f146d7c
commit 5b86ee393f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 17 additions and 82 deletions

View File

@ -17,8 +17,6 @@ APP_KEY=test-key
API_BASE_PATH=/api/
API_BASE_URL=
PROXY_TARGET_URL=
# console | file | dailyRotateFile
LOGGER_TRANSPORT=
LOGGER_BASE_PATH=storage/logs
@ -58,48 +56,8 @@ CACHE_MEMORY_MAX=2000
################# STORAGE (Initialization only) #################
INIT_LANG=en-US
INIT_ROOT_EMAIL=admin@nocobase.com
INIT_ROOT_PASSWORD=admin123
INIT_ROOT_NICKNAME=Super Admin
INIT_ROOT_USERNAME=nocobase
# local or ali-oss
DEFAULT_STORAGE_TYPE=local
# LOCAL STORAGE
LOCAL_STORAGE_BASE_URL=/storage/uploads
LOCAL_STORAGE_DEST=storage/uploads
# ALI OSS STORAGE
ALI_OSS_STORAGE_BASE_URL=
ALI_OSS_REGION=oss-cn-beijing
ALI_OSS_ACCESS_KEY_ID=
ALI_OSS_ACCESS_KEY_SECRET=
ALI_OSS_BUCKET=
# Tencent COS STORAGE
TX_COS_STORAGE_BASE_URL=
TX_COS_REGION=ap-guangzhou
TX_COS_SECRET_ID=
TX_COS_SECRET_KEY=
TX_COS_BUCKET=
# AWS
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_S3_REGION=
AWS_S3_BUCKET=
AWS_S3_STORAGE_BASE_URL=
# ALI SMS VERIFY CODE CONFIG
INIT_ALI_SMS_ACCESS_KEY=
INIT_ALI_SMS_ACCESS_KEY_SECRET=
INIT_ALI_SMS_ENDPOINT=
INIT_ALI_SMS_VERIFY_CODE_TEMPLATE=
INIT_ALI_SMS_VERIFY_CODE_SIGN=
# use any string name (no space)
DEFAULT_SMS_VERIFY_CODE_PROVIDER=
# in nodejs 17+ that SSL v3 causes some ecosystem libraries to become incompatible. Configuring this option can prevent upgrading SSL V3
# NODE_OPTIONS=--openssl-legacy-provider

View File

@ -272,11 +272,15 @@ exports.initEnv = function initEnv() {
PLUGIN_STORAGE_PATH: resolve(process.cwd(), 'storage/plugins'),
MFSU_AD: 'none',
WS_PATH: '/ws',
SOCKET_PATH: 'storage/gateway.sock',
NODE_MODULES_PATH: resolve(process.cwd(), 'node_modules'),
PM2_HOME: resolve(process.cwd(), './storage/.pm2'),
PLUGIN_PACKAGE_PREFIX: '@nocobase/plugin-,@nocobase/plugin-sample-,@nocobase/preset-',
SERVER_TSCONFIG_PATH: './tsconfig.server.json',
PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), 'storage/playwright/.auth/admin.json'),
CACHE_DEFAULT_STORE: 'memory',
CACHE_MEMORY_MAX: 2000,
LOGGER_BASE_PATH: 'storage/logs',
};
if (

View File

@ -69,4 +69,4 @@ function createLogger(options: LoggerOptions = {}) {
return logger;
}
export { Logger, LoggerOptions, Transports, createLogger };
export { createLogger, Logger, LoggerOptions, Transports };

View File

@ -9,6 +9,9 @@ export default (app: Application) => {
.option('-c, --clean')
.option('--lang <lang>')
.action(async (options) => {
if (options.lang) {
process.env.INIT_APP_LANG = options.lang;
}
await app.install(options);
const reinstall = options.clean || options.force;
app.log.info(`app ${reinstall ? 'reinstalled' : 'installed'} successfully [v${app.getVersion()}]`);

View File

@ -13,25 +13,14 @@ async function getLang(ctx) {
if (enabledLanguages.includes(currentUser?.appLang)) {
lang = currentUser?.appLang;
}
if (ctx.request.query.locale) {
if (ctx.request.query.locale && enabledLanguages.includes(ctx.request.query.locale)) {
lang = ctx.request.query.locale;
}
return lang;
}
export class ClientPlugin extends Plugin {
async beforeLoad() {
// const cmd = this.app.findCommand('install');
// if (cmd) {
// cmd.option('--import-demo');
// }
this.app.on('afterInstall', async (app, options) => {
const [opts] = options?.cliArgs || [{}];
if (opts?.importDemo) {
//
}
});
}
async beforeLoad() {}
async install() {
const uiSchemas = this.db.getRepository<any>('uiSchemas');

View File

@ -8,7 +8,7 @@ export { default as storageTypes } from './storages';
export default class PluginFileManager extends Plugin {
storageType() {
return process.env.DEFAULT_STORAGE_TYPE ?? 'local';
return 'local';
}
async loadStorages(options?: { transaction: any }) {

View File

@ -1,7 +1,7 @@
import { Plugin } from '@nocobase/client';
class UsersPlugin extends Plugin {
export class PluginUsersClient extends Plugin {
async load() {}
}
export default UsersPlugin;
export default PluginUsersClient;

View File

@ -3,29 +3,10 @@ import { Plugin } from '@nocobase/server';
import { parse } from '@nocobase/utils';
import { resolve } from 'path';
import { namespace } from './';
import * as actions from './actions/users';
import { enUS, zhCN } from './locale';
export interface UserPluginConfig {
name?: string;
}
export default class UsersPlugin extends Plugin<UserPluginConfig> {
constructor(app, options) {
super(app, options);
}
export default class PluginUsersServer extends Plugin {
async beforeLoad() {
this.app.i18n.addResources('zh-CN', namespace, zhCN);
this.app.i18n.addResources('en-US', namespace, enUS);
const cmd = this.app.findCommand('install');
if (cmd) {
cmd.requiredOption('-u, --root-username <rootUsername>', '', process.env.INIT_ROOT_USERNAME);
cmd.requiredOption('-e, --root-email <rootEmail>', '', process.env.INIT_ROOT_EMAIL);
cmd.requiredOption('-p, --root-password <rootPassword>', '', process.env.INIT_ROOT_PASSWORD);
cmd.option('-n, --root-nickname <rootNickname>');
}
this.db.registerOperators({
$isCurrentUser(_, ctx) {
return {
@ -120,8 +101,8 @@ export default class UsersPlugin extends Plugin<UserPluginConfig> {
getInstallingData(options: any = {}) {
const { INIT_ROOT_NICKNAME, INIT_ROOT_PASSWORD, INIT_ROOT_EMAIL, INIT_ROOT_USERNAME } = process.env;
const {
rootEmail = INIT_ROOT_EMAIL,
rootPassword = INIT_ROOT_PASSWORD,
rootEmail = INIT_ROOT_EMAIL || 'admin@nocobase.com',
rootPassword = INIT_ROOT_PASSWORD || 'admin123',
rootNickname = INIT_ROOT_NICKNAME || 'Super Admin',
rootUsername = INIT_ROOT_USERNAME || 'nocobase',
} = options.users || options?.cliArgs?.[0] || {};