template中的initialze.prod过程允许上层定制port等配置

This commit is contained in:
Xu Chang 2023-12-08 11:57:24 +08:00
parent 62e6decf9b
commit 3fe8ed6c42
1 changed files with 35 additions and 18 deletions

View File

@ -1,7 +1,11 @@
import { initialize as init } from 'oak-general-business/es/initialize.prod';
import { SimpleConnector } from 'oak-domain/lib/utils/SimpleConnector';
import { EntityDict, storageSchema, ActionDefDict } from '@oak-app-domain';
import {
EntityDict,
storageSchema,
ActionDefDict,
} from '@oak-app-domain';
import { BackendRuntimeContext } from './context/BackendRuntimeContext';
import { FrontendRuntimeContext } from './context/FrontendRuntimeContext';
@ -11,28 +15,37 @@ import { makeException } from './types/Exception';
import { AspectDict } from './aspects/AspectDict';
import colorDict from './config/color';
import cacheSavedEntities from './config/cache';
import {
selectFreeEntities,
updateFreeDict,
authDeduceRelationMap,
} from './config/relation';
import { selectFreeEntities, updateFreeDict, authDeduceRelationMap } from './config/relation';
import { AppType } from '@oak-app-domain/Application/Schema';
import { AFD } from '@project/types/RuntimeCxt';
export default function initialize(type: AppType, hostname: string) {
let protocol = '',
apiPath: string | undefined,
port: number | undefined;
if (type === 'wechatMp') {
protocol =
process.env.NODE_ENV === 'development' ? 'http://' : 'https://';
} else {
protocol = window.location.protocol;
export default function initialize(
type: AppType,
hostname: string,
protocolInput?: 'http:' | 'https:',
apiPathInput?: string,
portInput?: number
) {
let protocol = protocolInput!,
apiPath = apiPathInput,
port = portInput;
if (!protocol) {
if (type === 'wechatMp') {
protocol = process.env.NODE_ENV === 'development' ? 'http:' : 'https:';
} else if (type === 'web') {
protocol = window.location.protocol as 'http:';
} else {
protocol = 'http:';
}
}
port = process.env.NODE_ENV === 'development' ? 3001 : undefined;
apiPath = process.env.NODE_ENV === 'development' ? undefined : '/oak-api';
if (!port) {
port = process.env.NODE_ENV === 'development' ? 3001 : undefined; // 此处dev环境默认不经过nginx映射与configuration/server.json中一致。prod环境与线上映射一致默认为不设置
}
if (!apiPath) {
apiPath = process.env.NODE_ENV === 'development' ? undefined : '/oak-api'; // 此处dev环境默认不经过nginx映射为空prod环境设置与nginx中的路径映射对应
}
const connector = new SimpleConnector<EntityDict, FrontendRuntimeContext>(
{
@ -53,7 +66,11 @@ export default function initialize(type: AppType, hostname: string) {
type,
hostname,
storageSchema,
() => (store) => new FrontendRuntimeContext(store, wholeFeatures),
() => (store) =>
new FrontendRuntimeContext(
store,
wholeFeatures
),
connector,
checkers,
{