vona-core 5.0.89 → 5.0.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,7 @@ export class VonaApplication extends KoaApplication {
21
21
  const koaOptions = {
22
22
  env: cast(env).NODE_ENV,
23
23
  keys: options.config.server.keys,
24
- proxy: options.config.proxy.enabled,
24
+ proxy: options.config.proxy.enable,
25
25
  subdomainOffset: options.config.server.subdomainOffset,
26
26
  proxyIpHeader: options.config.proxy.ipHeaders,
27
27
  maxIpsCount: options.config.proxy.maxIpsCount,
@@ -4,9 +4,11 @@ import type { VonaConfigEnv } from '../../types/utils/env.ts';
4
4
  import type { PowerPartial } from '../../types/utils/powerPartial.ts';
5
5
  import type { VonaApplication } from './application.ts';
6
6
  export declare function combineAppConfigDefault(appInfo: VonaAppInfo, env: VonaConfigEnv): PowerPartial<import("../../types/config/config.ts").VonaConfig>;
7
- export declare function configDefault(appInfo: VonaAppInfo, env: VonaConfigEnv): VonaConfigOptional;
7
+ export declare function configDefault(_appInfo: VonaAppInfo, _env: VonaConfigEnv): VonaConfigOptional;
8
8
  export declare function configDev(_env: VonaConfigEnv): VonaConfigOptional;
9
9
  export declare function configProd(_env: VonaConfigEnv): VonaConfigOptional;
10
10
  export declare function configTest(_env: VonaConfigEnv): VonaConfigOptional;
11
11
  export type TypeConfigLoader<T> = (app: VonaApplication) => Promise<PowerPartial<T>>;
12
12
  export declare function combineConfigDefault<T>(app: VonaApplication, configDefault: TypeConfigLoader<T>, configDev?: TypeConfigLoader<T>, configProd?: TypeConfigLoader<T>, configTest?: TypeConfigLoader<T>): Promise<PowerPartial<T>>;
13
+ export declare function getLoggerPathPhysicalRoot(appInfo: VonaAppInfo): string;
14
+ export declare function getPublicPathPhysicalRoot(appInfo: VonaAppInfo): string;
@@ -1,7 +1,6 @@
1
1
  import os from 'node:os';
2
2
  import path from 'node:path';
3
3
  import fse from 'fs-extra';
4
- import { cast } from "../../types/utils/cast.js";
5
4
  import { deepExtend } from "../utils/util.js";
6
5
  export function combineAppConfigDefault(appInfo, env) {
7
6
  let config = configDefault(appInfo, env);
@@ -17,63 +16,33 @@ export function combineAppConfigDefault(appInfo, env) {
17
16
  }
18
17
  return config;
19
18
  }
20
- export function configDefault(appInfo, env) {
21
- // server
22
- const publicDir = env.SERVER_PUBLICDIR || getPublicPathPhysicalRoot(appInfo);
23
- const loggerDir = env.SERVER_LOGGERDIR || getLoggerPathPhysicalRoot(appInfo);
24
- const subdomainOffset = Number.parseInt(env.SERVER_SUBDOMAINOFFSET || '1');
25
- const workers = Number.parseInt(env.SERVER_WORKERS);
26
- return {
27
- meta: {
28
- flavor: cast(env).META_FLAVOR,
29
- mode: cast(env).META_MODE,
30
- },
31
- server: {
32
- keys: (env.SERVER_KEYS || '').split(','),
33
- globalPrefix: env.SERVER_GLOBALPREFIX || '/api',
34
- publicDir,
35
- loggerDir,
36
- subdomainOffset,
37
- workers,
38
- listen: {
39
- hostname: env.SERVER_LISTEN_HOSTNAME,
40
- port: Number.parseInt(env.SERVER_LISTEN_PORT),
41
- disable: env.SERVER_LISTEN_DISABLE === 'true',
42
- },
43
- serve: {},
44
- },
45
- proxy: {
46
- enabled: true,
47
- ipHeaders: 'x-real-ip,x-forwarded-for',
48
- hostHeaders: 'x-forwarded-host,host',
49
- protocolHeaders: 'x-forwarded-proto',
50
- maxProxyCount: 1,
51
- maxIpsCount: 15,
52
- },
53
- };
19
+ export function configDefault(_appInfo, _env) {
20
+ return {};
54
21
  }
55
22
  export function configDev(_env) {
56
- return {
57
- proxy: {
58
- enabled: true,
59
- },
60
- };
23
+ return {};
61
24
  }
62
25
  export function configProd(_env) {
63
- return {
64
- proxy: {
65
- enabled: true,
66
- },
67
- };
26
+ return {};
68
27
  }
69
28
  export function configTest(_env) {
70
- return {
71
- proxy: {
72
- enabled: false,
73
- },
74
- };
29
+ return {};
75
30
  }
76
- function getLoggerPathPhysicalRoot(appInfo) {
31
+ export async function combineConfigDefault(app, configDefault, configDev, configProd, configTest) {
32
+ let config = await configDefault(app);
33
+ const mode = app.config.meta.mode;
34
+ if (mode === 'dev' && configDev) {
35
+ config = deepExtend(config, await configDev(app));
36
+ }
37
+ else if (mode === 'prod' && configProd) {
38
+ config = deepExtend(config, await configProd(app));
39
+ }
40
+ else if (mode === 'test' && configTest) {
41
+ config = deepExtend(config, await configTest(app));
42
+ }
43
+ return config;
44
+ }
45
+ export function getLoggerPathPhysicalRoot(appInfo) {
77
46
  const mode = appInfo.configMeta.mode;
78
47
  let loggerDir;
79
48
  if (mode === 'test' || mode === 'dev') {
@@ -85,7 +54,7 @@ function getLoggerPathPhysicalRoot(appInfo) {
85
54
  fse.ensureDirSync(loggerDir);
86
55
  return loggerDir;
87
56
  }
88
- function getPublicPathPhysicalRoot(appInfo) {
57
+ export function getPublicPathPhysicalRoot(appInfo) {
89
58
  const mode = appInfo.configMeta.mode;
90
59
  let publicDir;
91
60
  if (mode === 'test' || mode === 'dev') {
@@ -97,17 +66,3 @@ function getPublicPathPhysicalRoot(appInfo) {
97
66
  fse.ensureDirSync(publicDir);
98
67
  return publicDir;
99
68
  }
100
- export async function combineConfigDefault(app, configDefault, configDev, configProd, configTest) {
101
- let config = await configDefault(app);
102
- const mode = app.config.meta.mode;
103
- if (mode === 'dev' && configDev) {
104
- config = deepExtend(config, await configDev(app));
105
- }
106
- else if (mode === 'prod' && configProd) {
107
- config = deepExtend(config, await configProd(app));
108
- }
109
- else if (mode === 'test' && configTest) {
110
- config = deepExtend(config, await configTest(app));
111
- }
112
- return config;
113
- }
@@ -61,7 +61,7 @@ export class AppLogger extends BeanSimple {
61
61
  }, Winston);
62
62
  }
63
63
  createTransportFile(fileName, clientInfo, options) {
64
- const dirname = this.app.config.server.loggerDir;
64
+ const dirname = this.app.config.logger.baseDir;
65
65
  if (!fse.existsSync(dirname)) {
66
66
  const [_, err] = catchErrorSync(() => {
67
67
  fse.ensureDirSync(dirname);
@@ -32,11 +32,11 @@ export declare class AppUtil extends BeanSimple {
32
32
  combineApiPathControllerAndActionRaw(moduleName: ModuleInfo.IModuleInfo | string, controllerPath: string | undefined, actionPath: RegExp | string | undefined, simplify?: boolean): string;
33
33
  combineApiPathControllerAndAction(moduleName: ModuleInfo.IModuleInfo | string, controllerPath: string | undefined, actionPath: RegExp | string | undefined, prefix?: string | boolean, simplify?: boolean): string;
34
34
  combineApiPath(path: string | undefined, moduleName?: ModuleInfo.IModuleInfo | string, prefix?: string | boolean, simplify?: boolean): string;
35
- combineStaticPath(path: string | undefined, moduleName?: ModuleInfo.IModuleInfo | string): string;
35
+ combineStaticPath(staticPath: string | undefined, moduleName?: ModuleInfo.IModuleInfo | string): string;
36
36
  combineResourceName(resourceName: string | undefined, moduleName: ModuleInfo.IModuleInfo | string, simplify?: boolean, simplifyProviderId?: boolean): string;
37
37
  getPublicPathPhysical(subdir?: string, ensure?: boolean): Promise<string>;
38
38
  get prodRootPath(): string;
39
- getAssetPathPhysical(moduleName: ModuleInfo.IModuleInfo | string, scene: keyof IModuleAssetSceneRecord, assetPath?: string): string | undefined;
39
+ getAssetPathPhysical(moduleName: ModuleInfo.IModuleInfo | string, scene: keyof IModuleAssetSceneRecord, assetPath?: string): string;
40
40
  createError(data: any, returnObject?: boolean): any;
41
41
  monkeyModule(ebAppMonkey: any, ebModulesMonkey: any, monkeyName: TypeMonkeyName, moduleTarget?: IModule, ...monkeyData: any[]): Promise<void>;
42
42
  monkeyModuleSync(ebAppMonkey: any, ebModulesMonkey: any, monkeyName: TypeMonkeyName, moduleTarget?: IModule, ...monkeyData: any[]): void;
@@ -62,5 +62,5 @@ export declare function prepareEnv(env: Partial<NodeJS.ProcessEnv>): VonaConfigE
62
62
  export declare function beanFullNameFromOnionName(onionName: string, sceneName: keyof IBeanSceneRecord): keyof IBeanRecord;
63
63
  export declare function onionNameFromBeanFullName(beanFullName: string, sceneName: keyof IBeanSceneRecord): string;
64
64
  export declare function filterHeaders(headers: object | undefined, whitelist: string[]): {} | undefined;
65
- export declare function combineFilePathSafe(dir: string, file: string): string | undefined;
65
+ export declare function combineFilePathSafe(dir: string, file: string): string;
66
66
  export {};
@@ -40,16 +40,20 @@ export class AppUtil extends BeanSimple {
40
40
  combineApiPath(path, moduleName, prefix, simplify) {
41
41
  return combineApiPath(path, moduleName, prefix, simplify, this.app.config.server.globalPrefix);
42
42
  }
43
- combineStaticPath(path, moduleName) {
43
+ combineStaticPath(staticPath, moduleName) {
44
44
  const globalPrefix = '/api/static';
45
- if (!path)
46
- path = '';
45
+ if (!staticPath)
46
+ staticPath = '';
47
+ // safe
48
+ staticPath = path.normalize(staticPath);
49
+ if (staticPath.includes('..'))
50
+ throw new Error(`unsafe path: ${staticPath}`);
47
51
  // ignore globalPrefix
48
- if (path.startsWith('//'))
49
- return path.substring(1);
52
+ if (staticPath.startsWith('//'))
53
+ return staticPath.substring(1);
50
54
  // ignore module path
51
- if (path.startsWith('/'))
52
- return `${globalPrefix}${path}`;
55
+ if (staticPath.startsWith('/'))
56
+ return `${globalPrefix}${staticPath}`;
53
57
  // globalPrefix + module path + arg
54
58
  if (!moduleName)
55
59
  throw new Error('should specify the moduleName');
@@ -57,7 +61,7 @@ export class AppUtil extends BeanSimple {
57
61
  moduleName = moduleName.relativeName;
58
62
  const parts = moduleName.split('-');
59
63
  // path
60
- return `${globalPrefix}/${parts[0]}/${parts[1]}/${path}`;
64
+ return `${globalPrefix}/${parts[0]}/${parts[1]}/${staticPath}`;
61
65
  }
62
66
  combineResourceName(resourceName, moduleName, simplify, simplifyProviderId) {
63
67
  return combineResourceName(resourceName, moduleName, simplify, simplifyProviderId);
@@ -300,6 +304,6 @@ export function combineFilePathSafe(dir, file) {
300
304
  const fullPath = path.normalize(path.join(dir, file));
301
305
  // files that can be accessd should be under options.dir
302
306
  if (fullPath.indexOf(dir) !== 0)
303
- return;
307
+ throw new Error(`unsafe dir: ${dir}`);
304
308
  return fullPath;
305
309
  }
@@ -7,7 +7,6 @@ export interface VonaConfig {
7
7
  keys: string[];
8
8
  globalPrefix: string;
9
9
  publicDir: string;
10
- loggerDir: string;
11
10
  subdomainOffset: number;
12
11
  workers: number;
13
12
  listen: {
@@ -21,7 +20,7 @@ export interface VonaConfig {
21
20
  };
22
21
  };
23
22
  proxy: {
24
- enabled: boolean;
23
+ enable: boolean;
25
24
  ipHeaders: string;
26
25
  hostHeaders: string;
27
26
  protocolHeaders: string;
@@ -16,6 +16,7 @@ export interface ILoggerRotateConfig {
16
16
  options: TypeLoggerRotateOptions;
17
17
  }
18
18
  export interface ConfigLogger {
19
+ baseDir: string;
19
20
  base: TypeLoggerOptions;
20
21
  clients: Record<keyof ILoggerClientRecord, TypeLoggerOptions>;
21
22
  rotate: ILoggerRotateConfig;
@@ -6,13 +6,13 @@ export interface VonaConfigEnv {
6
6
  SERVER_KEYS: string | undefined;
7
7
  SERVER_GLOBALPREFIX: string | undefined;
8
8
  SERVER_PUBLICDIR: string | undefined;
9
- SERVER_LOGGERDIR: string | undefined;
10
9
  SERVER_SUBDOMAINOFFSET: string | undefined;
11
10
  SERVER_WORKERS: string | undefined;
12
11
  SERVER_LISTEN_HOSTNAME: string | undefined;
13
12
  SERVER_LISTEN_PORT: string | undefined;
14
13
  SERVER_LISTEN_DISABLE: 'true' | 'false' | undefined;
15
14
  TEST_WHYISNODERUNNING: string | undefined;
15
+ LOGGER_DIR: string | undefined;
16
16
  LOGGER_DUMMY: 'true' | 'false' | undefined;
17
17
  LOGGER_ROTATE_ENABLE: 'true' | 'false' | undefined;
18
18
  LOGGER_ROTATE_FILENAME: string | undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-core",
3
3
  "type": "module",
4
- "version": "5.0.89",
4
+ "version": "5.0.92",
5
5
  "description": "vona",
6
6
  "publishConfig": {
7
7
  "access": "public"