File tree Expand file tree Collapse file tree 6 files changed +55
-7
lines changed
Expand file tree Collapse file tree 6 files changed +55
-7
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { builtLoaders } from "./builtInLoaders";
55import { CONF_RESERVEDS , ENV_NAME } from "./constants" ;
66import { CONFIG_ENTITY_KEY , ConfigLoader } from "../ConfigLoader" ;
77import { Container } from "../IoCLoader" ;
8- import { dirname , normalize } from "path" ;
8+ import { dirname , normalize , resolve } from "path" ;
99import { EventEmitter } from "events" ;
1010import { existsSync } from "fs" ;
1111import { IApplication } from "./IApplication" ;
@@ -103,14 +103,26 @@ export class Application extends EventEmitter implements IApplication {
103103 return builtLoaders ;
104104 }
105105
106+ /**
107+ * 字符串是不是一个路戏
108+ * @param str 字符串
109+ */
110+ private isPath ( str : string ) {
111+ if ( ! str ) return false ;
112+ return str . startsWith ( "/" ) || str . startsWith ( "." ) || / ^ [ a - z ] + \: / i. test ( str ) ;
113+ }
114+
106115 /**
107116 * 加载一个 loader
108117 * @param name loader 名称
109118 */
110119 protected importLoader ( name : string ) : ILoaderConstructor {
120+ name = String ( name ) ;
111121 const { root } = this . options ;
112- const path = normalize ( `${ root } /node_modules/${ String ( name ) } ` ) ;
113- const loader = require ( path ) ;
122+ const loaderPath = this . isPath ( name )
123+ ? resolve ( root , name )
124+ : normalize ( `${ root } /node_modules/${ name } ` ) ;
125+ const loader = require ( loaderPath ) ;
114126 return loader . default || loader ;
115127 }
116128
Original file line number Diff line number Diff line change 1- port : 8080
1+ # -----------------------------------------------------------------------------
2+ # 基础配置
3+ # 应用默认将自动选取一个可用端口,可在此指定监听端口
4+ # 此外,也可在 Application 实例化时,通过 options 指定端口
5+ # -----------------------------------------------------------------------------
26
3- loaders:
7+ # prot: 8080
8+
9+
10+ # -----------------------------------------------------------------------------
11+ # 配置 Loader 第一步:
12+ # 在此声明要在当前应用启用的 loader,格式为 `<CONF_NAME>: <包括名路径>`
13+ # 如果有需要,也可在此禁用内建 loader,格式为 `<CONF_NAME>: false`
14+ # -----------------------------------------------------------------------------
15+
16+ loaders :
17+ # loader_conf_name: loader_package
18+
19+
20+ # -----------------------------------------------------------------------------
21+ # 配置 Loader 第二步:
22+ # 在此配置已经启用的 loader
23+ # 如有需要,内建 loaders 也可直接在此配置或禁用,格式为 `<CONF_NAME>: false`
24+ # -----------------------------------------------------------------------------
25+
26+ # loader_conf_name:
27+ # option_a: ...
28+ # option_b: ...
29+
30+
31+ # -----------------------------------------------------------------------------
32+ # 自定义配置
33+ # 除了「基础配置」和「Loader 配置」,可在此添加自定义配置
34+ # 可在 controller/service/model 中,通过 `@config(<path>)` 注入配置内容
35+ # 另外,配置的整体内容,可通过全局应用实例获取(示例代码:`app.config`)
36+ # -----------------------------------------------------------------------------
37+
38+ # custom_conf_name:
39+ # option_a: ...
40+ # option_b: ...
Original file line number Diff line number Diff line change 11import { Application } from "../.." ;
22
3- const application = new Application ( ) ;
4- application
3+ new Application ( )
54 . launch ( )
65 . then ( ( { port } ) => console . info ( "Running:" , `http://localhost:${ port } ` ) )
76 . catch ( err => console . error ( err ) ) ;
You can’t perform that action at this time.
0 commit comments