From df8f05f4d8815ad13b5ed32e28f899598c9dbb63 Mon Sep 17 00:00:00 2001 From: Xc Date: Tue, 16 Apr 2024 15:37:09 +0800 Subject: [PATCH] =?UTF-8?q?start=E4=B8=AD=E7=9A=84=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=B0=8F=E9=97=AE=E9=A2=98=EF=BC=8Ctemplate=E4=B8=ADaccess.pro?= =?UTF-8?q?d=E7=9A=84=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/server/start.d.ts | 3 +-- lib/server/start.js | 9 ++++++++- lib/template.js | 24 ----------------------- src/server/start.ts | 9 +++++++-- template/src/configuration/access.prod.ts | 4 ++-- 5 files changed, 18 insertions(+), 31 deletions(-) diff --git a/lib/server/start.d.ts b/lib/server/start.d.ts index 967f985..8c0934e 100644 --- a/lib/server/start.d.ts +++ b/lib/server/start.d.ts @@ -4,5 +4,4 @@ import { Connector, EntityDict } from 'oak-domain/lib/types'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; import { SyncContext } from 'oak-domain/lib/store/SyncRowStore'; -import { AccessConfiguration } from 'oak-domain/lib/types/Configuration'; -export declare function startup>(path: string, connector: Connector, accessConfiguration: AccessConfiguration, omitWatchers?: boolean, omitTimers?: boolean, routine?: (context: AsyncContext) => Promise): Promise; +export declare function startup>(path: string, connector: Connector, omitWatchers?: boolean, omitTimers?: boolean, routine?: (context: AsyncContext) => Promise): Promise; diff --git a/lib/server/start.js b/lib/server/start.js index c1429d3..f7b1fb2 100644 --- a/lib/server/start.js +++ b/lib/server/start.js @@ -5,6 +5,7 @@ const tslib_1 = require("tslib"); /// require("./polyfill"); const http_1 = require("http"); +const path_1 = require("path"); const koa_1 = tslib_1.__importDefault(require("koa")); const koa_router_1 = tslib_1.__importDefault(require("koa-router")); const koa_body_1 = tslib_1.__importDefault(require("koa-body")); @@ -15,7 +16,7 @@ const sticky_1 = require("@socket.io/sticky"); const socket_io_1 = require("socket.io"); const DATA_SUBSCRIBER_NAMESPACE = '/ds'; const SERVER_SUBSCRIBER_NAMESPACE = process.env.OAK_SSUB_NAMESPACE || '/ssub'; -async function startup(path, connector, accessConfiguration, omitWatchers, omitTimers, routine) { +async function startup(path, connector, omitWatchers, omitTimers, routine) { const koa = new koa_1.default(); // socket const httpServer = (0, http_1.createServer)(koa.callback()); @@ -98,6 +99,12 @@ async function startup(path, connector, accessConfiguration, omitWatchers, omitT response.body = res.body; return; }); + const filenameDict = { + 'development': 'access.dev', + 'staging': 'access.staging', + 'production': 'access.prod', + }; + const accessConfiguration = require((0, path_1.join)(path, 'lib', 'configuration', filenameDict[process.env.NODE_ENV])).default; // 外部socket接口 router.get(connector.getSubscribePointRouter(), async (ctx) => { const { response } = ctx; diff --git a/lib/template.js b/lib/template.js index e90a1dd..ab42415 100644 --- a/lib/template.js +++ b/lib/template.js @@ -351,18 +351,6 @@ function tsConfigBuildPathsJsonContent() { "@oak-app-domain/*": [ "src/oak-app-domain/*" ], - "@oak-general-business": [ - "node_modules/oak-general-business/lib/index" - ], - "@oak-general-business/*": [ - "node_modules/oak-general-business/lib/*" - ], - "@oak-frontend-base": [ - "node_modules/oak-frontend-base/lib/index" - ], - "@oak-frontend-base/*": [ - "node_modules/oak-frontend-base/lib/*" - ], }, "typeRoots": ["./typings"] } @@ -383,18 +371,6 @@ function tsConfigPathsJsonContent() { "@oak-app-domain/*": [ "src/oak-app-domain/*" ], - "@oak-general-business": [ - "node_modules/oak-general-business/es/index" - ], - "@oak-general-business/*": [ - "node_modules/oak-general-business/es/*" - ], - "@oak-frontend-base": [ - "node_modules/oak-frontend-base/es/index" - ], - "@oak-frontend-base/*": [ - "node_modules/oak-frontend-base/es/*" - ], }, "typeRoots": ["./typings"] } diff --git a/src/server/start.ts b/src/server/start.ts index 5f46918..69e45b7 100644 --- a/src/server/start.ts +++ b/src/server/start.ts @@ -1,7 +1,7 @@ /// import './polyfill'; import { IncomingHttpHeaders, createServer } from "http"; -import PathLib from 'path'; +import PathLib, { join } from 'path'; import Koa from 'koa'; import KoaRouter from 'koa-router'; import KoaBody from 'koa-body'; @@ -21,7 +21,6 @@ const SERVER_SUBSCRIBER_NAMESPACE = process.env.OAK_SSUB_NAMESPACE || '/ssub'; export async function startup>( path: string, connector: Connector, - accessConfiguration: AccessConfiguration, omitWatchers?: boolean, omitTimers?: boolean, routine?: (context: AsyncContext) => Promise, @@ -115,6 +114,12 @@ export async function startup { const { response } = ctx; diff --git a/template/src/configuration/access.prod.ts b/template/src/configuration/access.prod.ts index f4d32f3..ebadff4 100644 --- a/template/src/configuration/access.prod.ts +++ b/template/src/configuration/access.prod.ts @@ -1,5 +1,5 @@ import { AccessConfiguration } from 'oak-domain/lib/types/Configuration'; - +import devConfiguration from './access.dev'; const accessConfiguration: AccessConfiguration = { http: { hostname: 'www.oak-framework.test', @@ -8,4 +8,4 @@ const accessConfiguration: AccessConfiguration = { }, }; -export default accessConfiguration; +export default process.env.NODE_ENV === 'development' ? devConfiguration : accessConfiguration;