UNPKG

1.65 kBJavaScriptView Raw
1let facade = require('./Facade')
2
3let env = !!process.env.sys ? JSON.parse(process.env.sys) : {
4 serverType: facade.CoreOfLogic.mapping[0], //待调测的服务器类型
5 serverId: 1, //待调测的服务器编号
6 portal: true //兼任门户(充当索引服务器),注意索引服务器只能有一台,因此该配置信息具有排他性
7};
8
9if(env.constructor == String){
10 env = JSON.parse(env);
11}
12
13(async () => {
14 //系统主引导流程,除了必须传递运行环境变量 env,也可以搭载任意变量,这些变量都将合并为核心类的options对象的属性,供运行时访问
15 if(env.portal) { //如果该服务器兼任门户,则启动索引服务
16 await facade.boot({
17 env:{
18 serverType: "Index",
19 serverId: 1
20 }
21 });
22 }
23
24 //可以使用如下方法添加路由:
25 //1. 在 facade.boot 传入参数 static 中配置静态资源映射类路由
26 //2. 在 facade.boot 传入参数 static 中配置动态函数类路由,自动注入节点对象,但不能运用中间件,也无法注入用户对象
27 //3. 在控制器的 router 属性中配置动态函数类路由,优点是可以运用各种中间件如参数解析/用户鉴权、自动注入节点对象/用户对象,等等
28 await facade.boot({
29 env: env,
30 //设置附加路由
31 static: [
32 ['/client/', './web/client'],
33 ['/echo', params => {
34 return 'OK';
35 }],
36 ]
37 }).then(core => {
38
39 });
40})();