koatty 3.3.7 → 3.4.6
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.
- package/.eslintrc.js +2 -1
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +6 -0
- package/LICENSE +1 -1
- package/README.md +5 -0
- package/babel.config.js +0 -5
- package/demo/static/test.css +3 -0
- package/demo/tsconfig.json +66 -0
- package/dist/config/config.d.ts +1 -1
- package/dist/config/config.js +1 -1
- package/dist/config/config.js.map +1 -1
- package/dist/config/middleware.d.ts +4 -6
- package/dist/config/middleware.js +7 -16
- package/dist/config/middleware.js.map +1 -1
- package/dist/config/router.js +20 -16
- package/dist/config/router.js.map +1 -1
- package/dist/controller/BaseController.d.ts +0 -97
- package/dist/controller/BaseController.js +2 -146
- package/dist/controller/BaseController.js.map +1 -1
- package/dist/controller/HttpController.d.ts +131 -0
- package/dist/controller/HttpController.js +215 -0
- package/dist/controller/HttpController.js.map +1 -0
- package/dist/core/Bootstrap.d.ts +19 -0
- package/dist/core/Bootstrap.js +66 -17
- package/dist/core/Bootstrap.js.map +1 -1
- package/dist/core/Component.d.ts +2 -11
- package/dist/core/Component.js.map +1 -1
- package/dist/core/Loader.d.ts +13 -36
- package/dist/core/Loader.js +50 -80
- package/dist/core/Loader.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/middleware/PayloadMiddleware.js +3 -3
- package/dist/middleware/PayloadMiddleware.js.map +1 -1
- package/dist/middleware/TraceMiddleware.d.ts +11 -0
- package/dist/middleware/TraceMiddleware.js +22 -0
- package/dist/middleware/TraceMiddleware.js.map +1 -0
- package/dist/service/BaseService.js +1 -2
- package/dist/service/BaseService.js.map +1 -1
- package/dist/util/Helper.js +2 -2
- package/dist/util/Helper.js.map +1 -1
- package/dist/util/Logger.d.ts +21 -1
- package/dist/util/Logger.js +32 -3
- package/dist/util/Logger.js.map +1 -1
- package/jest.config.js +19 -1
- package/jest_html_reporters.html +1 -1
- package/package.json +30 -25
- package/tsconfig.json +1 -1
- package/dist/controller/RestController.d.ts +0 -56
- package/dist/controller/RestController.js +0 -202
- package/dist/controller/RestController.js.map +0 -1
- package/dist/core/Router.d.ts +0 -15
- package/dist/core/Router.js +0 -19
- package/dist/core/Router.js.map +0 -1
- package/dist/core/Serve.d.ts +0 -8
- package/dist/core/Serve.js +0 -62
- package/dist/core/Serve.js.map +0 -1
@@ -0,0 +1,131 @@
|
|
1
|
+
import { Koatty, KoattyContext } from 'koatty_core';
|
2
|
+
import { ApiInput, ApiOutput } from '../core/Component';
|
3
|
+
import { BaseController } from "./BaseController";
|
4
|
+
/**
|
5
|
+
* HTTP controller
|
6
|
+
*
|
7
|
+
* @export
|
8
|
+
* @class HttpController
|
9
|
+
* @implements {IController}
|
10
|
+
*/
|
11
|
+
export declare class HttpController extends BaseController {
|
12
|
+
app: Koatty;
|
13
|
+
ctx: KoattyContext;
|
14
|
+
/**
|
15
|
+
* Whether it is a GET request
|
16
|
+
*
|
17
|
+
* @public
|
18
|
+
* @returns {boolean}
|
19
|
+
* @memberof HttpController
|
20
|
+
*/
|
21
|
+
isGet(): boolean;
|
22
|
+
/**
|
23
|
+
* Whether it is a POST request
|
24
|
+
*
|
25
|
+
* @public
|
26
|
+
* @returns {boolean}
|
27
|
+
* @memberof HttpController
|
28
|
+
*/
|
29
|
+
isPost(): boolean;
|
30
|
+
/**
|
31
|
+
* Determines whether the METHOD request is specified
|
32
|
+
*
|
33
|
+
* @public
|
34
|
+
* @param {string} method
|
35
|
+
* @returns {boolean}
|
36
|
+
* @memberof HttpController
|
37
|
+
*/
|
38
|
+
isMethod(method: string): boolean;
|
39
|
+
/**
|
40
|
+
* Get/Set headers.
|
41
|
+
*
|
42
|
+
* @public
|
43
|
+
* @param {string} [name]
|
44
|
+
* @param {*} [value]
|
45
|
+
* @returns {*}
|
46
|
+
* @memberof HttpController
|
47
|
+
*/
|
48
|
+
header(name?: string, value?: any): any;
|
49
|
+
/**
|
50
|
+
* Get POST/GET parameters, the POST value is priority.
|
51
|
+
*
|
52
|
+
* @param {string} [name]
|
53
|
+
* @returns
|
54
|
+
* @memberof HttpController
|
55
|
+
*/
|
56
|
+
param(name?: string): Promise<any>;
|
57
|
+
/**
|
58
|
+
* Set response content-type
|
59
|
+
*
|
60
|
+
* @public
|
61
|
+
* @param {string} contentType
|
62
|
+
* @param {(string | boolean)} [encoding]
|
63
|
+
* @returns {string}
|
64
|
+
* @memberof HttpController
|
65
|
+
*/
|
66
|
+
type(contentType: string, encoding?: string | boolean): string;
|
67
|
+
/**
|
68
|
+
* set cache-control and expires header
|
69
|
+
*
|
70
|
+
* @public
|
71
|
+
* @param {number} [timeout=30]
|
72
|
+
* @returns {void}
|
73
|
+
* @memberof HttpController
|
74
|
+
*/
|
75
|
+
expires(timeout?: number): void;
|
76
|
+
/**
|
77
|
+
* Url redirect
|
78
|
+
*
|
79
|
+
* @param {string} urls
|
80
|
+
* @param {string} [alt]
|
81
|
+
* @returns {void}
|
82
|
+
* @memberof HttpController
|
83
|
+
*/
|
84
|
+
redirect(urls: string, alt?: string): void;
|
85
|
+
/**
|
86
|
+
* Block access
|
87
|
+
*
|
88
|
+
* @param {number} [code=403]
|
89
|
+
* @returns {Promise<any>}
|
90
|
+
* @memberof HttpController
|
91
|
+
*/
|
92
|
+
deny(code?: number): Promise<any>;
|
93
|
+
/**
|
94
|
+
* Set response Body content
|
95
|
+
*
|
96
|
+
* @param {*} data
|
97
|
+
* @param {string} [contentType]
|
98
|
+
* @param {string} [encoding]
|
99
|
+
* @returns {Promise<any>}
|
100
|
+
* @memberof HttpController
|
101
|
+
*/
|
102
|
+
body(data: any, contentType?: string, encoding?: string): Promise<any>;
|
103
|
+
/**
|
104
|
+
* Respond to json formatted content
|
105
|
+
*
|
106
|
+
* @param {*} data
|
107
|
+
* @returns {Promise<any>}
|
108
|
+
* @memberof HttpController
|
109
|
+
*/
|
110
|
+
json(data: any): Promise<any>;
|
111
|
+
/**
|
112
|
+
* Response to normalize json format content for success
|
113
|
+
*
|
114
|
+
* @param {(string | ApiInput)} msg 待处理的message消息
|
115
|
+
* @param {*} [data] 待处理的数据
|
116
|
+
* @param {number} [code=200] 错误码,默认0
|
117
|
+
* @returns {Promise<ApiOutput>}
|
118
|
+
* @memberof HttpController
|
119
|
+
*/
|
120
|
+
ok(msg: string | ApiInput, data?: any, code?: number): Promise<ApiOutput>;
|
121
|
+
/**
|
122
|
+
* Response to normalize json format content for fail
|
123
|
+
*
|
124
|
+
* @param {(string | ApiInput)} msg
|
125
|
+
* @param {*} [data]
|
126
|
+
* @param {number} [code=1]
|
127
|
+
* @returns {Promise<ApiOutput>}
|
128
|
+
* @memberof HttpController
|
129
|
+
*/
|
130
|
+
fail(msg: Error | string | ApiInput, data?: any, code?: number): Promise<ApiOutput>;
|
131
|
+
}
|
@@ -0,0 +1,215 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.HttpController = void 0;
|
4
|
+
/**
|
5
|
+
* @ author: richen
|
6
|
+
* @ copyright: Copyright (c) - <richenlin(at)gmail.com>
|
7
|
+
* @ license: BSD (3-Clause)
|
8
|
+
* @ version: 2020-05-20 15:45:24
|
9
|
+
*/
|
10
|
+
const Helper_1 = require("../util/Helper");
|
11
|
+
const BaseController_1 = require("./BaseController");
|
12
|
+
/**
|
13
|
+
* HTTP controller
|
14
|
+
*
|
15
|
+
* @export
|
16
|
+
* @class HttpController
|
17
|
+
* @implements {IController}
|
18
|
+
*/
|
19
|
+
class HttpController extends BaseController_1.BaseController {
|
20
|
+
/**
|
21
|
+
* Whether it is a GET request
|
22
|
+
*
|
23
|
+
* @public
|
24
|
+
* @returns {boolean}
|
25
|
+
* @memberof HttpController
|
26
|
+
*/
|
27
|
+
isGet() {
|
28
|
+
return this.ctx.method === "GET";
|
29
|
+
}
|
30
|
+
/**
|
31
|
+
* Whether it is a POST request
|
32
|
+
*
|
33
|
+
* @public
|
34
|
+
* @returns {boolean}
|
35
|
+
* @memberof HttpController
|
36
|
+
*/
|
37
|
+
isPost() {
|
38
|
+
return this.ctx.method === "POST";
|
39
|
+
}
|
40
|
+
/**
|
41
|
+
* Determines whether the METHOD request is specified
|
42
|
+
*
|
43
|
+
* @public
|
44
|
+
* @param {string} method
|
45
|
+
* @returns {boolean}
|
46
|
+
* @memberof HttpController
|
47
|
+
*/
|
48
|
+
isMethod(method) {
|
49
|
+
return this.ctx.method === method.toUpperCase();
|
50
|
+
}
|
51
|
+
/**
|
52
|
+
* Get/Set headers.
|
53
|
+
*
|
54
|
+
* @public
|
55
|
+
* @param {string} [name]
|
56
|
+
* @param {*} [value]
|
57
|
+
* @returns {*}
|
58
|
+
* @memberof HttpController
|
59
|
+
*/
|
60
|
+
header(name, value) {
|
61
|
+
if (name === undefined) {
|
62
|
+
return this.ctx.headers;
|
63
|
+
}
|
64
|
+
if (value === undefined) {
|
65
|
+
return this.ctx.get(name);
|
66
|
+
}
|
67
|
+
return this.ctx.set(name, value);
|
68
|
+
}
|
69
|
+
/**
|
70
|
+
* Get POST/GET parameters, the POST value is priority.
|
71
|
+
*
|
72
|
+
* @param {string} [name]
|
73
|
+
* @returns
|
74
|
+
* @memberof HttpController
|
75
|
+
*/
|
76
|
+
param(name) {
|
77
|
+
return this.ctx.bodyParser().then((body) => {
|
78
|
+
const getParams = this.ctx.queryParser() || {};
|
79
|
+
const postParams = (body.post ? body.post : body) || {};
|
80
|
+
if (name !== undefined) {
|
81
|
+
return postParams[name] === undefined ? getParams[name] : postParams[name];
|
82
|
+
}
|
83
|
+
return { ...getParams, ...postParams };
|
84
|
+
});
|
85
|
+
}
|
86
|
+
/**
|
87
|
+
* Set response content-type
|
88
|
+
*
|
89
|
+
* @public
|
90
|
+
* @param {string} contentType
|
91
|
+
* @param {(string | boolean)} [encoding]
|
92
|
+
* @returns {string}
|
93
|
+
* @memberof HttpController
|
94
|
+
*/
|
95
|
+
type(contentType, encoding) {
|
96
|
+
if (encoding !== false && !contentType.includes("charset")) {
|
97
|
+
contentType = `${contentType}; charset=${encoding || this.app.config("encoding")}`;
|
98
|
+
}
|
99
|
+
this.ctx.type = contentType;
|
100
|
+
return contentType;
|
101
|
+
}
|
102
|
+
/**
|
103
|
+
* set cache-control and expires header
|
104
|
+
*
|
105
|
+
* @public
|
106
|
+
* @param {number} [timeout=30]
|
107
|
+
* @returns {void}
|
108
|
+
* @memberof HttpController
|
109
|
+
*/
|
110
|
+
expires(timeout = 30) {
|
111
|
+
timeout = Helper_1.Helper.toNumber(timeout) * 1000;
|
112
|
+
const date = new Date(Date.now() + timeout);
|
113
|
+
this.ctx.set("Cache-Control", `max-age=${timeout}`);
|
114
|
+
return this.ctx.set("Expires", date.toUTCString());
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* Url redirect
|
118
|
+
*
|
119
|
+
* @param {string} urls
|
120
|
+
* @param {string} [alt]
|
121
|
+
* @returns {void}
|
122
|
+
* @memberof HttpController
|
123
|
+
*/
|
124
|
+
redirect(urls, alt) {
|
125
|
+
return this.ctx.redirect(urls, alt);
|
126
|
+
}
|
127
|
+
/**
|
128
|
+
* Block access
|
129
|
+
*
|
130
|
+
* @param {number} [code=403]
|
131
|
+
* @returns {Promise<any>}
|
132
|
+
* @memberof HttpController
|
133
|
+
*/
|
134
|
+
deny(code = 403) {
|
135
|
+
return this.ctx.throw(code);
|
136
|
+
}
|
137
|
+
/**
|
138
|
+
* Set response Body content
|
139
|
+
*
|
140
|
+
* @param {*} data
|
141
|
+
* @param {string} [contentType]
|
142
|
+
* @param {string} [encoding]
|
143
|
+
* @returns {Promise<any>}
|
144
|
+
* @memberof HttpController
|
145
|
+
*/
|
146
|
+
body(data, contentType, encoding) {
|
147
|
+
contentType = contentType || "text/plain";
|
148
|
+
encoding = encoding || this.app.config("encoding") || "utf-8";
|
149
|
+
this.type(contentType, encoding);
|
150
|
+
this.ctx.body = data;
|
151
|
+
// return this.app.prevent();
|
152
|
+
return null;
|
153
|
+
}
|
154
|
+
/**
|
155
|
+
* Respond to json formatted content
|
156
|
+
*
|
157
|
+
* @param {*} data
|
158
|
+
* @returns {Promise<any>}
|
159
|
+
* @memberof HttpController
|
160
|
+
*/
|
161
|
+
json(data) {
|
162
|
+
return this.body(data, "application/json");
|
163
|
+
}
|
164
|
+
/**
|
165
|
+
* Response to normalize json format content for success
|
166
|
+
*
|
167
|
+
* @param {(string | ApiInput)} msg 待处理的message消息
|
168
|
+
* @param {*} [data] 待处理的数据
|
169
|
+
* @param {number} [code=200] 错误码,默认0
|
170
|
+
* @returns {Promise<ApiOutput>}
|
171
|
+
* @memberof HttpController
|
172
|
+
*/
|
173
|
+
ok(msg, data, code = 0) {
|
174
|
+
const obj = this.formatApiData(msg, data, code);
|
175
|
+
return this.json(obj);
|
176
|
+
}
|
177
|
+
/**
|
178
|
+
* Response to normalize json format content for fail
|
179
|
+
*
|
180
|
+
* @param {(string | ApiInput)} msg
|
181
|
+
* @param {*} [data]
|
182
|
+
* @param {number} [code=1]
|
183
|
+
* @returns {Promise<ApiOutput>}
|
184
|
+
* @memberof HttpController
|
185
|
+
*/
|
186
|
+
fail(msg, data, code = 1) {
|
187
|
+
const obj = this.formatApiData(msg, data, code);
|
188
|
+
return this.json(obj);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
exports.HttpController = HttpController;
|
192
|
+
// const properties = ["constructor", "init"];
|
193
|
+
// export const HttpController = new Proxy(Base, {
|
194
|
+
// set(target, key, value, receiver) {
|
195
|
+
// if (Reflect.get(target, key, receiver) === undefined) {
|
196
|
+
// return Reflect.set(target, key, value, receiver);
|
197
|
+
// } else if (key === "init") {
|
198
|
+
// return Reflect.set(target, key, value, receiver);
|
199
|
+
// } else {
|
200
|
+
// throw Error("Cannot redefine getter-only property");
|
201
|
+
// }
|
202
|
+
// },
|
203
|
+
// deleteProperty(target, key) {
|
204
|
+
// throw Error("Cannot delete getter-only property");
|
205
|
+
// },
|
206
|
+
// construct(target, args, newTarget) {
|
207
|
+
// Reflect.ownKeys(target.prototype).map((n) => {
|
208
|
+
// if (newTarget.prototype.hasOwnProperty(n) && !properties.includes(Helper.toString(n))) {
|
209
|
+
// throw Error(`Cannot override the final method "${Helper.toString(n)}"`);
|
210
|
+
// }
|
211
|
+
// });
|
212
|
+
// return Reflect.construct(target, args, newTarget);
|
213
|
+
// }
|
214
|
+
// });
|
215
|
+
//# sourceMappingURL=HttpController.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"HttpController.js","sourceRoot":"","sources":["../../src/controller/HttpController.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,2CAAwC;AAGxC,qDAAkD;AAElD;;;;;;GAMG;AACH,MAAa,cAAe,SAAQ,+BAAc;IAI9C;;;;;;OAMG;IACI,KAAK;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,KAAK,CAAC;IACrC,CAAC;IAED;;;;;;OAMG;IACI,MAAM;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC;IACtC,CAAC;IAED;;;;;;;OAOG;IACI,QAAQ,CAAC,MAAc;QAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,IAAa,EAAE,KAAW;QACpC,IAAI,IAAI,KAAK,SAAS,EAAE;YACpB,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;SAC3B;QACD,IAAI,KAAK,KAAK,SAAS,EAAE;YACrB,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SAC7B;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,IAAa;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,I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C,CAAC;QAC3D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CAEJ;AA3LD,wCA2LC;AAGD,8CAA8C;AAC9C,kDAAkD;AAClD,0CAA0C;AAC1C,kEAAkE;AAClE,gEAAgE;AAChE,uCAAuC;AACvC,gEAAgE;AAChE,mBAAmB;AACnB,mEAAmE;AACnE,YAAY;AACZ,SAAS;AACT,oCAAoC;AACpC,6DAA6D;AAC7D,SAAS;AACT,2CAA2C;AAC3C,yDAAyD;AACzD,uGAAuG;AACvG,2FAA2F;AAC3F,gBAAgB;AAChB,cAAc;AACd,6DAA6D;AAC7D,QAAQ;AACR,MAAM"}
|
package/dist/core/Bootstrap.d.ts
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
* @ version: 2020-07-06 11:22:58
|
6
6
|
*/
|
7
7
|
import "reflect-metadata";
|
8
|
+
import { Koatty } from 'koatty_core';
|
8
9
|
/**
|
9
10
|
* Bootstrap application
|
10
11
|
*
|
@@ -29,3 +30,21 @@ export declare function ComponentScan(scanPath?: string | string[]): ClassDecora
|
|
29
30
|
* @returns {ClassDecorator}
|
30
31
|
*/
|
31
32
|
export declare function ConfigurationScan(scanPath?: string | string[]): ClassDecorator;
|
33
|
+
export declare type AppReadyHookFunc = (app: Koatty) => Promise<any>;
|
34
|
+
/**
|
35
|
+
* bind AppReadyHookFunc
|
36
|
+
* example:
|
37
|
+
* export function TestDecorator(): ClassDecorator {
|
38
|
+
* return (target: any) => {
|
39
|
+
* BindAppReadyHook((app: Koatty) => {
|
40
|
+
* // todo
|
41
|
+
* return Promise.resolve();
|
42
|
+
* }, target)
|
43
|
+
* }
|
44
|
+
* }
|
45
|
+
*
|
46
|
+
* @export
|
47
|
+
* @param {AppReadyHookFunc} func
|
48
|
+
* @param {*} target
|
49
|
+
*/
|
50
|
+
export declare function BindAppReadyHook(func: AppReadyHookFunc, target: any): void;
|
package/dist/core/Bootstrap.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ConfigurationScan = exports.ComponentScan = exports.Bootstrap = void 0;
|
3
|
+
exports.BindAppReadyHook = exports.ConfigurationScan = exports.ComponentScan = exports.Bootstrap = void 0;
|
4
4
|
/**
|
5
5
|
* @ author: richen
|
6
6
|
* @ copyright: Copyright (c) - <richenlin(at)gmail.com>
|
@@ -15,9 +15,9 @@ const Helper_1 = require("../util/Helper");
|
|
15
15
|
const Logger_1 = require("../util/Logger");
|
16
16
|
const koatty_container_1 = require("koatty_container");
|
17
17
|
const koatty_serve_1 = require("koatty_serve");
|
18
|
-
const Router_1 = require("./Router");
|
19
|
-
const Serve_1 = require("./Serve");
|
20
18
|
const Constants_1 = require("./Constants");
|
19
|
+
const koatty_router_1 = require("koatty_router");
|
20
|
+
const pkg = require("../../package.json");
|
21
21
|
/**
|
22
22
|
* execute bootstrap
|
23
23
|
*
|
@@ -27,7 +27,7 @@ const Constants_1 = require("./Constants");
|
|
27
27
|
*/
|
28
28
|
const ExecBootstrap = async function (target, bootFunc) {
|
29
29
|
// checked runtime
|
30
|
-
Helper_1.checkRuntime();
|
30
|
+
(0, Helper_1.checkRuntime)();
|
31
31
|
const app = Reflect.construct(target, []);
|
32
32
|
try {
|
33
33
|
console.log(Constants_1.LOGO);
|
@@ -36,6 +36,8 @@ const ExecBootstrap = async function (target, bootFunc) {
|
|
36
36
|
if (!(app instanceof koatty_core_1.Koatty)) {
|
37
37
|
throw new Error(`class ${target.name} does not inherit from Koatty`);
|
38
38
|
}
|
39
|
+
// version
|
40
|
+
Helper_1.Helper.define(app, "version", pkg.version);
|
39
41
|
// exec bootFunc
|
40
42
|
if (Helper_1.Helper.isFunction(bootFunc)) {
|
41
43
|
Logger_1.Logger.Custom('think', '', 'Execute bootFunc ...');
|
@@ -45,11 +47,12 @@ const ExecBootstrap = async function (target, bootFunc) {
|
|
45
47
|
Loader_1.Loader.initialize(app);
|
46
48
|
// Set IOC.app
|
47
49
|
koatty_container_1.IOCContainer.setApp(app);
|
50
|
+
Helper_1.Helper.define(app, "container", koatty_container_1.IOCContainer);
|
48
51
|
Logger_1.Logger.Custom('think', '', 'ComponentScan ...');
|
49
52
|
// component metadata
|
50
|
-
const componentMetas = Loader_1.Loader.GetComponentMetas(
|
53
|
+
const componentMetas = Loader_1.Loader.GetComponentMetas(app, target);
|
51
54
|
// configuration metadata
|
52
|
-
const configurationMetas = Loader_1.Loader.GetConfigurationMetas(target);
|
55
|
+
const configurationMetas = Loader_1.Loader.GetConfigurationMetas(app, target);
|
53
56
|
// load all bean
|
54
57
|
const exSet = new Set();
|
55
58
|
Loader_1.Loader.LoadDirectory(componentMetas, '', (fileName, target, xpath) => {
|
@@ -66,31 +69,29 @@ const ExecBootstrap = async function (target, bootFunc) {
|
|
66
69
|
Loader_1.Loader.LoadConfigs(app, configurationMetas);
|
67
70
|
// Load Plugin
|
68
71
|
Logger_1.Logger.Custom('think', '', 'Load Plugins ...');
|
69
|
-
await Loader_1.Loader.LoadPlugins(app
|
72
|
+
await Loader_1.Loader.LoadPlugins(app);
|
70
73
|
// Set Logger
|
71
74
|
Loader_1.Loader.SetLogger(app);
|
72
75
|
// Load App ready hooks
|
73
|
-
Loader_1.Loader.LoadAppReadyHooks(
|
76
|
+
Loader_1.Loader.LoadAppReadyHooks(app, target);
|
74
77
|
// New router
|
75
|
-
const KoattyRouter =
|
76
|
-
// Middleware may depend on
|
77
|
-
Helper_1.Helper.define(app, "Router", KoattyRouter);
|
78
|
+
const KoattyRouter = newRouter(app);
|
78
79
|
// Load Middleware
|
79
80
|
Logger_1.Logger.Custom('think', '', 'Load Middlewares ...');
|
80
|
-
await Loader_1.Loader.LoadMiddlewares(app
|
81
|
+
await Loader_1.Loader.LoadMiddlewares(app);
|
81
82
|
// Emit app ready event
|
82
83
|
Logger_1.Logger.Custom('think', '', 'Emit App Ready ...');
|
83
84
|
// app.emit("appReady");
|
84
85
|
await asyncEvent(app, 'appReady');
|
85
86
|
// Load Components
|
86
87
|
Logger_1.Logger.Custom('think', '', 'Load Components ...');
|
87
|
-
Loader_1.Loader.LoadComponents(app
|
88
|
+
Loader_1.Loader.LoadComponents(app);
|
88
89
|
// Load Services
|
89
90
|
Logger_1.Logger.Custom('think', '', 'Load Services ...');
|
90
|
-
Loader_1.Loader.LoadServices(app
|
91
|
+
Loader_1.Loader.LoadServices(app);
|
91
92
|
// Load Controllers
|
92
93
|
Logger_1.Logger.Custom('think', '', 'Load Controllers ...');
|
93
|
-
Loader_1.Loader.LoadControllers(app
|
94
|
+
Loader_1.Loader.LoadControllers(app);
|
94
95
|
// Load Routers
|
95
96
|
Logger_1.Logger.Custom('think', '', 'Load Routers ...');
|
96
97
|
KoattyRouter.LoadRouter(app.getMetaData("_controllers"));
|
@@ -100,15 +101,43 @@ const ExecBootstrap = async function (target, bootFunc) {
|
|
100
101
|
await asyncEvent(app, 'appStart');
|
101
102
|
Logger_1.Logger.Custom('think', '', '====================================');
|
102
103
|
// Start server
|
103
|
-
|
104
|
+
app.listen(newServe(app));
|
105
|
+
console.log(Logger_1.Logger.Debug("dont print"));
|
104
106
|
// binding event "appStop"
|
105
|
-
koatty_serve_1.BindProcessEvent(app, 'appStop');
|
107
|
+
(0, koatty_serve_1.BindProcessEvent)(app, 'appStop');
|
106
108
|
}
|
107
109
|
catch (err) {
|
108
110
|
Logger_1.Logger.Error(err);
|
109
111
|
process.exit();
|
110
112
|
}
|
111
113
|
};
|
114
|
+
/**
|
115
|
+
* create router
|
116
|
+
*
|
117
|
+
* @export
|
118
|
+
* @param {Koatty} app
|
119
|
+
* @returns {*}
|
120
|
+
*/
|
121
|
+
const newRouter = function (app) {
|
122
|
+
var _a;
|
123
|
+
const protocol = app.config("protocol") || "http";
|
124
|
+
const options = (_a = app.config(undefined, 'router')) !== null && _a !== void 0 ? _a : {};
|
125
|
+
const router = (0, koatty_router_1.NewRouter)(app, options, protocol);
|
126
|
+
Helper_1.Helper.define(app, "router", router);
|
127
|
+
return router;
|
128
|
+
};
|
129
|
+
/**
|
130
|
+
* create serve
|
131
|
+
*
|
132
|
+
* @param {Koatty} app
|
133
|
+
* @returns {*}
|
134
|
+
*/
|
135
|
+
const newServe = function (app) {
|
136
|
+
const protocol = app.config("protocol") || "http";
|
137
|
+
const server = (0, koatty_serve_1.Serve)(app, protocol);
|
138
|
+
Helper_1.Helper.define(app, "server", server);
|
139
|
+
return server;
|
140
|
+
};
|
112
141
|
/**
|
113
142
|
* Execute event as async
|
114
143
|
*
|
@@ -177,4 +206,24 @@ function ConfigurationScan(scanPath) {
|
|
177
206
|
};
|
178
207
|
}
|
179
208
|
exports.ConfigurationScan = ConfigurationScan;
|
209
|
+
/**
|
210
|
+
* bind AppReadyHookFunc
|
211
|
+
* example:
|
212
|
+
* export function TestDecorator(): ClassDecorator {
|
213
|
+
* return (target: any) => {
|
214
|
+
* BindAppReadyHook((app: Koatty) => {
|
215
|
+
* // todo
|
216
|
+
* return Promise.resolve();
|
217
|
+
* }, target)
|
218
|
+
* }
|
219
|
+
* }
|
220
|
+
*
|
221
|
+
* @export
|
222
|
+
* @param {AppReadyHookFunc} func
|
223
|
+
* @param {*} target
|
224
|
+
*/
|
225
|
+
function BindAppReadyHook(func, target) {
|
226
|
+
koatty_container_1.IOCContainer.attachClassMetadata(koatty_container_1.TAGGED_CLS, Constants_1.APP_READY_HOOK, func, target);
|
227
|
+
}
|
228
|
+
exports.BindAppReadyHook = BindAppReadyHook;
|
180
229
|
//# sourceMappingURL=Bootstrap.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Bootstrap.js","sourceRoot":"","sources":["../../src/core/Bootstrap.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,kDAAkD;AAClD,4BAA0B;AAE1B,
|
1
|
+
{"version":3,"file":"Bootstrap.js","sourceRoot":"","sources":["../../src/core/Bootstrap.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,kDAAkD;AAClD,4BAA0B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YAAY,oBAAM,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACzD;QACD,QAAQ,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC;QAC1B,+BAAY,CAAC,iBAAiB,CAAC,6BAAU,EAAE,8BAAkB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACrF,CAAC,CAAC;AACN,CAAC;AAVD,8CAUC;AAKD;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,gBAAgB,CAAC,IAAsB,EAAE,MAAW;IAChE,+BAAY,CAAC,mBAAmB,CAAC,6BAAU,EAAE,0BAAc,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAC/E,CAAC;AAFD,4CAEC"}
|
package/dist/core/Component.d.ts
CHANGED
@@ -45,19 +45,10 @@ export interface ApiInput {
|
|
45
45
|
export interface IController {
|
46
46
|
app: Koatty;
|
47
47
|
ctx: KoattyContext;
|
48
|
-
|
49
|
-
|
50
|
-
readonly expires: (timeout: number) => void;
|
48
|
+
__befor?: () => Promise<any>;
|
49
|
+
__after?: () => Promise<any>;
|
51
50
|
readonly fail: (msg?: Error | string | ApiInput, data?: any, ret?: number) => Promise<ApiOutput>;
|
52
|
-
readonly header: (name: string, value?: any) => any;
|
53
|
-
readonly json: (data: any) => Promise<any>;
|
54
|
-
readonly isGet: () => boolean;
|
55
|
-
readonly isMethod: (method: string) => boolean;
|
56
|
-
readonly isPost: () => boolean;
|
57
51
|
readonly ok: (msg?: string | ApiInput, data?: any, ret?: number) => Promise<ApiOutput>;
|
58
|
-
readonly param: (name?: string) => any;
|
59
|
-
readonly redirect: (urls: string, alt?: string) => void;
|
60
|
-
readonly type: (contentType?: string, encoding?: string | boolean) => string;
|
61
52
|
}
|
62
53
|
/**
|
63
54
|
* Indicates that an decorated class is a "middleware".
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Component.js","sourceRoot":"","sources":["../../src/core/Component.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,kDAAkD;AAClD,4BAA0B;AAE1B,uDAAgD;AAEhD,iDAAkD;AAElD;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,UAAmB;IACzC,OAAO,CAAC,MAAW,EAAE,EAAE;QACnB,UAAU,GAAG,UAAU,IAAI,+BAAY,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC9D,+BAAY,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC5D,CAAC,CAAC;AACN,CAAC;AALD,8BAKC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,IAAI,GAAG,EAAE;IAChC,OAAO,CAAC,MAAW,EAAE,EAAE;QACnB,MAAM,UAAU,GAAG,+BAAY,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACtD,+BAAY,CAAC,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;QACzD,+BAAY,CAAC,gBAAgB,CAAC,iCAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC/E,CAAC,CAAC;AACN,CAAC;AAND,gCAMC;
|
1
|
+
{"version":3,"file":"Component.js","sourceRoot":"","sources":["../../src/core/Component.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,kDAAkD;AAClD,4BAA0B;AAE1B,uDAAgD;AAEhD,iDAAkD;AAElD;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,UAAmB;IACzC,OAAO,CAAC,MAAW,EAAE,EAAE;QACnB,UAAU,GAAG,UAAU,IAAI,+BAAY,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC9D,+BAAY,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC5D,CAAC,CAAC;AACN,CAAC;AALD,8BAKC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,IAAI,GAAG,EAAE;IAChC,OAAO,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