routup 0.4.1 → 0.6.0
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/README.md +7 -6
- package/dist/constants.d.ts +4 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -0
- package/dist/constants.js.map +1 -1
- package/dist/handler/type.d.ts +0 -3
- package/dist/handler/type.d.ts.map +1 -1
- package/dist/handler/utils.d.ts +1 -4
- package/dist/handler/utils.d.ts.map +1 -1
- package/dist/handler/utils.js +1 -28
- package/dist/handler/utils.js.map +1 -1
- package/dist/helpers/response/send-stream.d.ts +2 -4
- package/dist/helpers/response/send-stream.d.ts.map +1 -1
- package/dist/helpers/response/send-stream.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/route/module.d.ts +3 -0
- package/dist/route/module.d.ts.map +1 -1
- package/dist/route/module.js +26 -2
- package/dist/route/module.js.map +1 -1
- package/dist/router/module.d.ts +6 -5
- package/dist/router/module.d.ts.map +1 -1
- package/dist/router/module.js +50 -75
- package/dist/router/module.js.map +1 -1
- package/dist/type.d.ts +0 -3
- package/dist/type.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/object.d.ts +2 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/{decorators/method/type.js → utils/object.js} +8 -1
- package/dist/utils/object.js.map +1 -0
- package/package.json +2 -2
- package/dist/decorators/controller/index.d.ts +0 -2
- package/dist/decorators/controller/index.d.ts.map +0 -1
- package/dist/decorators/controller/index.js +0 -24
- package/dist/decorators/controller/index.js.map +0 -1
- package/dist/decorators/controller/module.d.ts +0 -4
- package/dist/decorators/controller/module.d.ts.map +0 -1
- package/dist/decorators/controller/module.js +0 -29
- package/dist/decorators/controller/module.js.map +0 -1
- package/dist/decorators/index.d.ts +0 -5
- package/dist/decorators/index.d.ts.map +0 -1
- package/dist/decorators/index.js +0 -27
- package/dist/decorators/index.js.map +0 -1
- package/dist/decorators/method/arguments.d.ts +0 -4
- package/dist/decorators/method/arguments.d.ts.map +0 -1
- package/dist/decorators/method/arguments.js +0 -22
- package/dist/decorators/method/arguments.js.map +0 -1
- package/dist/decorators/method/index.d.ts +0 -4
- package/dist/decorators/method/index.d.ts.map +0 -1
- package/dist/decorators/method/index.js +0 -26
- package/dist/decorators/method/index.js.map +0 -1
- package/dist/decorators/method/module.d.ts +0 -8
- package/dist/decorators/method/module.d.ts.map +0 -1
- package/dist/decorators/method/module.js +0 -46
- package/dist/decorators/method/module.js.map +0 -1
- package/dist/decorators/method/type.d.ts +0 -7
- package/dist/decorators/method/type.d.ts.map +0 -1
- package/dist/decorators/method/type.js.map +0 -1
- package/dist/decorators/parameter/index.d.ts +0 -3
- package/dist/decorators/parameter/index.d.ts.map +0 -1
- package/dist/decorators/parameter/index.js +0 -25
- package/dist/decorators/parameter/index.js.map +0 -1
- package/dist/decorators/parameter/module.d.ts +0 -10
- package/dist/decorators/parameter/module.d.ts.map +0 -1
- package/dist/decorators/parameter/module.js +0 -58
- package/dist/decorators/parameter/module.js.map +0 -1
- package/dist/decorators/parameter/type.d.ts +0 -8
- package/dist/decorators/parameter/type.d.ts.map +0 -1
- package/dist/decorators/parameter/type.js +0 -9
- package/dist/decorators/parameter/type.js.map +0 -1
- package/dist/decorators/type.d.ts +0 -14
- package/dist/decorators/type.d.ts.map +0 -1
- package/dist/decorators/type.js +0 -9
- package/dist/decorators/type.js.map +0 -1
- package/dist/decorators/utils/index.d.ts +0 -2
- package/dist/decorators/utils/index.d.ts.map +0 -1
- package/dist/decorators/utils/index.js +0 -24
- package/dist/decorators/utils/index.js.map +0 -1
- package/dist/decorators/utils/meta.d.ts +0 -3
- package/dist/decorators/utils/meta.d.ts.map +0 -1
- package/dist/decorators/utils/meta.js +0 -24
- package/dist/decorators/utils/meta.js.map +0 -1
package/README.md
CHANGED
|
@@ -62,12 +62,13 @@ router.listen(3000);
|
|
|
62
62
|
According to the fact that routup is a minimalistic framework, it depends on plugins to cover some
|
|
63
63
|
typically http framework functions, which are not integrated in the main package.
|
|
64
64
|
|
|
65
|
-
| Name
|
|
66
|
-
|
|
67
|
-
| [body](https://www.npmjs.com/package/@routup/body)
|
|
68
|
-
| [cookie](https://www.npmjs.com/package/@routup/cookie)
|
|
69
|
-
| [
|
|
70
|
-
| [
|
|
65
|
+
| Name | Description |
|
|
66
|
+
|-----------------------------------------------------------------|--------------------------------------------------------------------------|
|
|
67
|
+
| [body](https://www.npmjs.com/package/@routup/body) | Read and parse the request body. |
|
|
68
|
+
| [cookie](https://www.npmjs.com/package/@routup/cookie) | Read and parse request cookies and serialize cookies for the response. |
|
|
69
|
+
| [decorators](https://www.npmjs.com/package/@routup/decorators) | Create request handlers with class-, method- & parameter-decorators. |
|
|
70
|
+
| [query](https://www.npmjs.com/package/@routup/query) | Read and parse the query string of the request url. |
|
|
71
|
+
| [swagger](https://www.npmjs.com/package/@routup/swagger) | Serve generated docs from URL or based on a JSON file. |
|
|
71
72
|
|
|
72
73
|
## License
|
|
73
74
|
|
package/dist/constants.d.ts
CHANGED
|
@@ -3,13 +3,16 @@ export declare enum Method {
|
|
|
3
3
|
POST = "post",
|
|
4
4
|
PUT = "put",
|
|
5
5
|
PATCH = "patch",
|
|
6
|
-
DELETE = "delete"
|
|
6
|
+
DELETE = "delete",
|
|
7
|
+
OPTIONS = "options",
|
|
8
|
+
HEAD = "head"
|
|
7
9
|
}
|
|
8
10
|
export declare enum HeaderName {
|
|
9
11
|
ACCEPT = "accept",
|
|
10
12
|
ACCEPT_CHARSET = "accept-charset",
|
|
11
13
|
ACCEPT_ENCODING = "accept-encoding",
|
|
12
14
|
ACCEPT_LANGUAGE = "accept-language",
|
|
15
|
+
ALLOW = "allow",
|
|
13
16
|
CACHE_CONTROL = "cache-control",
|
|
14
17
|
CONTENT_DISPOSITION = "content-disposition",
|
|
15
18
|
CONTENT_ENCODING = "content-encoding",
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAOA,oBAAY,MAAM;IACd,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,MAAM,WAAW;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAOA,oBAAY,MAAM;IACd,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,IAAI,SAAS;CAChB;AAED,oBAAY,UAAU;IAClB,MAAM,WAAW;IACjB,cAAc,mBAAmB;IACjC,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,KAAK,UAAU;IACf,aAAa,kBAAkB;IAC/B,mBAAmB,wBAAwB;IAC3C,gBAAgB,qBAAqB;IACrC,cAAc,mBAAmB;IACjC,YAAY,iBAAiB;IAC7B,MAAM,WAAW;IACjB,aAAa,kBAAkB;IAC/B,QAAQ,aAAa;IACrB,UAAU,eAAe;CAC5B"}
|
package/dist/constants.js
CHANGED
|
@@ -14,6 +14,8 @@ var Method;
|
|
|
14
14
|
Method["PUT"] = "put";
|
|
15
15
|
Method["PATCH"] = "patch";
|
|
16
16
|
Method["DELETE"] = "delete";
|
|
17
|
+
Method["OPTIONS"] = "options";
|
|
18
|
+
Method["HEAD"] = "head";
|
|
17
19
|
})(Method = exports.Method || (exports.Method = {}));
|
|
18
20
|
var HeaderName;
|
|
19
21
|
(function (HeaderName) {
|
|
@@ -21,6 +23,7 @@ var HeaderName;
|
|
|
21
23
|
HeaderName["ACCEPT_CHARSET"] = "accept-charset";
|
|
22
24
|
HeaderName["ACCEPT_ENCODING"] = "accept-encoding";
|
|
23
25
|
HeaderName["ACCEPT_LANGUAGE"] = "accept-language";
|
|
26
|
+
HeaderName["ALLOW"] = "allow";
|
|
24
27
|
HeaderName["CACHE_CONTROL"] = "cache-control";
|
|
25
28
|
HeaderName["CONTENT_DISPOSITION"] = "content-disposition";
|
|
26
29
|
HeaderName["CONTENT_ENCODING"] = "content-encoding";
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,IAAY,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,IAAY,MAQX;AARD,WAAY,MAAM;IACd,qBAAW,CAAA;IACX,uBAAa,CAAA;IACb,qBAAW,CAAA;IACX,yBAAe,CAAA;IACf,2BAAiB,CAAA;IACjB,6BAAmB,CAAA;IACnB,uBAAa,CAAA;AACjB,CAAC,EARW,MAAM,GAAN,cAAM,KAAN,cAAM,QAQjB;AAED,IAAY,UAeX;AAfD,WAAY,UAAU;IAClB,+BAAiB,CAAA;IACjB,+CAAiC,CAAA;IACjC,iDAAmC,CAAA;IACnC,iDAAmC,CAAA;IACnC,6BAAe,CAAA;IACf,6CAA+B,CAAA;IAC/B,yDAA2C,CAAA;IAC3C,mDAAqC,CAAA;IACrC,+CAAiC,CAAA;IACjC,2CAA6B,CAAA;IAC7B,+BAAiB,CAAA;IACjB,6CAA+B,CAAA;IAC/B,mCAAqB,CAAA;IACrB,uCAAyB,CAAA;AAC7B,CAAC,EAfW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAerB"}
|
package/dist/handler/type.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { Next, Request, Response } from '../type';
|
|
2
2
|
export type Handler = (req: Request, res: Response, next: Next) => unknown;
|
|
3
3
|
export type ErrorHandler = (err: Error, req: Request, res: Response, next: Next) => unknown;
|
|
4
|
-
export interface HandlerInterface {
|
|
5
|
-
run(request: Request, response: Response, next: Next): Promise<void> | void;
|
|
6
|
-
}
|
|
7
4
|
//# sourceMappingURL=type.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/handler/type.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,MAAM,OAAO,GAAG,CAClB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,IAAI,KACT,OAAO,CAAC;AAEb,MAAM,MAAM,YAAY,GAAG,CACvB,GAAG,EAAE,KAAK,EACV,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,IAAI,KACT,OAAO,CAAC
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/handler/type.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,MAAM,OAAO,GAAG,CAClB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,IAAI,KACT,OAAO,CAAC;AAEb,MAAM,MAAM,YAAY,GAAG,CACvB,GAAG,EAAE,KAAK,EACV,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,IAAI,KACT,OAAO,CAAC"}
|
package/dist/handler/utils.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Handler, HandlerInterface } from './type';
|
|
3
|
-
export declare function isHandlerClassInstance(input: unknown): input is HandlerInterface;
|
|
4
|
-
export declare function createHandlerForClassType(item: ClassType): Handler;
|
|
1
|
+
import { Next, Response } from '../type';
|
|
5
2
|
export declare function processHandlerExecutionOutput(res: Response, next: Next, output?: unknown): void;
|
|
6
3
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/handler/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/handler/utils.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGzC,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,QAiBxF"}
|
package/dist/handler/utils.js
CHANGED
|
@@ -6,36 +6,9 @@
|
|
|
6
6
|
* view the LICENSE file that was distributed with this source code.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.processHandlerExecutionOutput =
|
|
10
|
-
const smob_1 = require("smob");
|
|
9
|
+
exports.processHandlerExecutionOutput = void 0;
|
|
11
10
|
const helpers_1 = require("../helpers");
|
|
12
11
|
const utils_1 = require("../utils");
|
|
13
|
-
function isHandlerClassInstance(input) {
|
|
14
|
-
return (0, smob_1.isObject)(input) &&
|
|
15
|
-
typeof input.run === 'function';
|
|
16
|
-
}
|
|
17
|
-
exports.isHandlerClassInstance = isHandlerClassInstance;
|
|
18
|
-
function createHandlerForClassType(item) {
|
|
19
|
-
return (req, res, next) => {
|
|
20
|
-
try {
|
|
21
|
-
const middle = new item();
|
|
22
|
-
if (isHandlerClassInstance(middle)) {
|
|
23
|
-
middle.run(req, res, next);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
/* istanbul ignore next */
|
|
27
|
-
middle(req, res, next);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
/* istanbul ignore next */
|
|
32
|
-
if (e instanceof Error) {
|
|
33
|
-
next(e);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
exports.createHandlerForClassType = createHandlerForClassType;
|
|
39
12
|
function processHandlerExecutionOutput(res, next, output) {
|
|
40
13
|
if ((0, utils_1.isPromise)(output)) {
|
|
41
14
|
output
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/handler/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/handler/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wCAAkC;AAElC,oCAAqC;AAErC,SAAgB,6BAA6B,CAAC,GAAa,EAAE,IAAU,EAAE,MAAgB;IACrF,IAAI,IAAA,iBAAS,EAAC,MAAM,CAAC,EAAE;QACnB,MAAM;aACD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACR,IAAI,OAAO,CAAC,KAAK,WAAW,EAAE;gBAC1B,IAAA,cAAI,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC;aAChB;YAED,OAAO,CAAC,CAAC;QACb,CAAC,CAAC;aACD,KAAK,CAAC,IAAI,CAAC,CAAC;QACjB,OAAO;KACV;IAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QAC/B,IAAA,cAAI,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;KACrB;AACL,CAAC;AAjBD,sEAiBC"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { ServerResponse } from 'http';
|
|
4
2
|
import { Readable } from 'stream';
|
|
5
|
-
import { Next } from '../../type';
|
|
6
|
-
export declare function sendStream(res:
|
|
3
|
+
import { Next, Response } from '../../type';
|
|
4
|
+
export declare function sendStream(res: Response, stream: Readable, fn?: Next): void;
|
|
7
5
|
//# sourceMappingURL=send-stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-stream.d.ts","sourceRoot":"","sources":["../../../src/helpers/response/send-stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"send-stream.d.ts","sourceRoot":"","sources":["../../../src/helpers/response/send-stream.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5C,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,IAAI,QAqBpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-stream.js","sourceRoot":"","sources":["../../../src/helpers/response/send-stream.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;
|
|
1
|
+
{"version":3,"file":"send-stream.js","sourceRoot":"","sources":["../../../src/helpers/response/send-stream.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAKH,SAAgB,UAAU,CAAC,GAAa,EAAE,MAAgB,EAAE,EAAS;IACjE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACnB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACvB,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE;YAC1B,EAAE,CAAC,GAAG,CAAC,CAAC;SACX;aAAM;YACH,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,EAAE,CAAC;SACb;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACpB,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE;YAC1B,EAAE,EAAE,CAAC;SACR;aAAM;YACH,GAAG,CAAC,GAAG,EAAE,CAAC;SACb;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AArBD,gCAqBC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from './constants';
|
|
2
|
-
export * from './decorators';
|
|
3
2
|
export * from './handler';
|
|
4
3
|
export * from './helpers';
|
|
5
4
|
export * from './layer';
|
|
@@ -7,4 +6,5 @@ export * from './path';
|
|
|
7
6
|
export * from './route';
|
|
8
7
|
export * from './router';
|
|
9
8
|
export * from './type';
|
|
9
|
+
export * from './utils';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
__exportStar(require("./constants"), exports);
|
|
24
|
-
__exportStar(require("./decorators"), exports);
|
|
25
24
|
__exportStar(require("./handler"), exports);
|
|
26
25
|
__exportStar(require("./helpers"), exports);
|
|
27
26
|
__exportStar(require("./layer"), exports);
|
|
@@ -29,4 +28,5 @@ __exportStar(require("./path"), exports);
|
|
|
29
28
|
__exportStar(require("./route"), exports);
|
|
30
29
|
__exportStar(require("./router"), exports);
|
|
31
30
|
__exportStar(require("./type"), exports);
|
|
31
|
+
__exportStar(require("./utils"), exports);
|
|
32
32
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,8CAA4B;AAC5B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,8CAA4B;AAC5B,4CAA0B;AAC1B,4CAA0B;AAC1B,0CAAwB;AACxB,yCAAuB;AACvB,0CAAwB;AACxB,2CAAyB;AACzB,yCAAuB;AACvB,0CAAwB"}
|
package/dist/route/module.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare class Route {
|
|
|
12
12
|
constructor(path: Path);
|
|
13
13
|
matchPath(path: string): boolean;
|
|
14
14
|
matchMethod(method: string): boolean;
|
|
15
|
+
getMethods(): string[];
|
|
15
16
|
dispatch(req: Request, res: Response, meta: DispatcherMeta, done: Next): void;
|
|
16
17
|
register(method: `${Method}`, ...handlers: Handler[]): void;
|
|
17
18
|
get(...handlers: Handler[]): void;
|
|
@@ -19,6 +20,8 @@ export declare class Route {
|
|
|
19
20
|
put(...handlers: Handler[]): void;
|
|
20
21
|
patch(...handlers: Handler[]): void;
|
|
21
22
|
delete(...handlers: Handler[]): void;
|
|
23
|
+
head(...handlers: Handler[]): void;
|
|
24
|
+
options(...handlers: Handler[]): void;
|
|
22
25
|
private isStrictPath;
|
|
23
26
|
}
|
|
24
27
|
//# sourceMappingURL=module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/route/module.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MA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MAAM,EAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAM;gBAIpC,IAAI,EAAE,IAAI;IAStB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAI,OAAO;IAIjC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAI,OAAO;IAerC,UAAU,IAAK,MAAM,EAAE;IAevB,QAAQ,CACJ,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,IAAI,GACV,IAAI;IAuDR,QAAQ,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE;IAcpD,GAAG,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI1B,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI3B,GAAG,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI1B,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI5B,MAAM,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI7B,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI3B,OAAO,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAM9B,OAAO,CAAC,YAAY;CAIvB"}
|
package/dist/route/module.js
CHANGED
|
@@ -25,7 +25,21 @@ class Route {
|
|
|
25
25
|
return this.pathMatcher.test(path);
|
|
26
26
|
}
|
|
27
27
|
matchMethod(method) {
|
|
28
|
-
|
|
28
|
+
let name = method.toLowerCase();
|
|
29
|
+
if (name === constants_1.Method.HEAD &&
|
|
30
|
+
!(0, smob_1.hasOwnProperty)(this.layers, name)) {
|
|
31
|
+
name = constants_1.Method.GET;
|
|
32
|
+
}
|
|
33
|
+
return Object.prototype.hasOwnProperty.call(this.layers, name);
|
|
34
|
+
}
|
|
35
|
+
// --------------------------------------------------
|
|
36
|
+
getMethods() {
|
|
37
|
+
const keys = Object.keys(this.layers);
|
|
38
|
+
if ((0, smob_1.hasOwnProperty)(this.layers, constants_1.Method.GET) &&
|
|
39
|
+
!(0, smob_1.hasOwnProperty)(this.layers, constants_1.Method.HEAD)) {
|
|
40
|
+
keys.push(constants_1.Method.HEAD);
|
|
41
|
+
}
|
|
42
|
+
return keys;
|
|
29
43
|
}
|
|
30
44
|
// --------------------------------------------------
|
|
31
45
|
dispatch(req, res, meta, done) {
|
|
@@ -33,7 +47,11 @@ class Route {
|
|
|
33
47
|
done();
|
|
34
48
|
return;
|
|
35
49
|
}
|
|
36
|
-
|
|
50
|
+
let name = req.method.toLowerCase();
|
|
51
|
+
if (name === constants_1.Method.HEAD &&
|
|
52
|
+
!(0, smob_1.hasOwnProperty)(this.layers, name)) {
|
|
53
|
+
name = constants_1.Method.GET;
|
|
54
|
+
}
|
|
37
55
|
const layers = this.layers[name];
|
|
38
56
|
if (typeof layers === 'undefined' ||
|
|
39
57
|
layers.length === 0 ||
|
|
@@ -81,6 +99,12 @@ class Route {
|
|
|
81
99
|
delete(...handlers) {
|
|
82
100
|
return this.register(constants_1.Method.DELETE, ...handlers);
|
|
83
101
|
}
|
|
102
|
+
head(...handlers) {
|
|
103
|
+
return this.register(constants_1.Method.HEAD, ...handlers);
|
|
104
|
+
}
|
|
105
|
+
options(...handlers) {
|
|
106
|
+
return this.register(constants_1.Method.OPTIONS, ...handlers);
|
|
107
|
+
}
|
|
84
108
|
// --------------------------------------------------
|
|
85
109
|
isStrictPath() {
|
|
86
110
|
return typeof this.path !== 'string' ||
|
package/dist/route/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/route/module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/route/module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+BAA6C;AAC7C,4CAAsC;AAEtC,oCAAiC;AACjC,kC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AAC;IAED,IAAI,CAAC,GAAG,QAAmB;QACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,kBAAM,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,CAAC,GAAG,QAAmB;QAC1B,OAAO,IAAI,CAAC,QAAQ,CAAC,kBAAM,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,qDAAqD;IAE7C,YAAY;QAChB,OAAO,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;YAChC,CAAC,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;IACtD,CAAC;CACJ;AApKD,sBAoKC"}
|
package/dist/router/module.d.ts
CHANGED
|
@@ -4,12 +4,13 @@ import { ErrorHandler, Handler } from '../handler';
|
|
|
4
4
|
import { PathMatcher } from '../path';
|
|
5
5
|
import { Layer } from '../layer';
|
|
6
6
|
import { Route } from '../route';
|
|
7
|
-
import {
|
|
7
|
+
import { DispatcherMeta, Next, Path, Request, Response } from '../type';
|
|
8
8
|
import { RouterOptions } from './type';
|
|
9
9
|
export declare function isRouterInstance(input: unknown): input is Router;
|
|
10
10
|
export declare class Router {
|
|
11
11
|
readonly '@instanceof': symbol;
|
|
12
|
-
protected
|
|
12
|
+
protected mountPath: Path | undefined;
|
|
13
|
+
protected timeout: number | undefined;
|
|
13
14
|
protected stack: (Router | Route | Layer)[];
|
|
14
15
|
protected pathMatcher: PathMatcher | undefined;
|
|
15
16
|
/**
|
|
@@ -19,7 +20,7 @@ export declare class Router {
|
|
|
19
20
|
*/
|
|
20
21
|
protected isRoot: boolean | undefined;
|
|
21
22
|
constructor(options?: RouterOptions);
|
|
22
|
-
|
|
23
|
+
setMountPath(value: Path): void;
|
|
23
24
|
createListener(): RequestListener;
|
|
24
25
|
listen(port: number): import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
25
26
|
matchPath(path: string): boolean;
|
|
@@ -31,13 +32,13 @@ export declare class Router {
|
|
|
31
32
|
post(path: Path, ...handlers: Handler[]): this;
|
|
32
33
|
put(path: Path, ...handlers: Handler[]): this;
|
|
33
34
|
patch(path: Path, ...handlers: Handler[]): this;
|
|
35
|
+
head(path: Path, ...handlers: Handler[]): this;
|
|
36
|
+
options(path: Path, ...handlers: Handler[]): this;
|
|
34
37
|
use(router: Router): this;
|
|
35
38
|
use(handler: Handler): this;
|
|
36
39
|
use(handler: ErrorHandler): this;
|
|
37
40
|
use(path: Path, router: Router): this;
|
|
38
41
|
use(path: Path, handler: Handler): this;
|
|
39
42
|
use(path: Path, handler: ErrorHandler): this;
|
|
40
|
-
useController(input: (ClassType | Record<string, any>)): void;
|
|
41
|
-
useControllers(input: (ClassType | Record<string, any>)[]): void;
|
|
42
43
|
}
|
|
43
44
|
//# sourceMappingURL=module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/router/module.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,eAAe,EAAgB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/router/module.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,eAAe,EAAgB,MAAM,MAAM,CAAC;AAGrD,OAAO,EACH,YAAY,EAAE,OAAO,EACxB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAStC,OAAO,EAAE,KAAK,EAAmB,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,KAAK,EAAmB,MAAM,UAAU,CAAC;AAClD,OAAO,EACH,cAAc,EACd,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,QAAQ,EACX,MAAM,SAAS,CAAC;AAKjB,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,wBAAgB,gBAAgB,CAAC,KAAK,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I,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAI,IAAI;IAOhD,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAI,IAAI;IAO/C,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAI,IAAI;IASlD,GAAG,CAAC,MAAM,EAAE,MAAM,GAAI,IAAI;IAE1B,GAAG,CAAC,OAAO,EAAE,OAAO,GAAI,IAAI;IAE5B,GAAG,CAAC,OAAO,EAAE,YAAY,GAAI,IAAI;IAEjC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAI,IAAI;IAEtC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,GAAI,IAAI;IAExC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,GAAI,IAAI;CA+BhD"}
|
package/dist/router/module.js
CHANGED
|
@@ -9,16 +9,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.Router = exports.isRouterInstance = void 0;
|
|
10
10
|
const http_1 = require("http");
|
|
11
11
|
const smob_1 = require("smob");
|
|
12
|
-
const
|
|
13
|
-
const utils_1 = require("../decorators/utils");
|
|
14
|
-
const handler_1 = require("../handler");
|
|
12
|
+
const constants_1 = require("../constants");
|
|
15
13
|
const path_1 = require("../path");
|
|
16
|
-
const
|
|
14
|
+
const utils_1 = require("../utils");
|
|
17
15
|
const layer_1 = require("../layer");
|
|
18
16
|
const route_1 = require("../route");
|
|
19
17
|
const helpers_1 = require("../helpers");
|
|
20
18
|
function isRouterInstance(input) {
|
|
21
|
-
return (0,
|
|
19
|
+
return (0, utils_1.isInstance)(input, 'Router');
|
|
22
20
|
}
|
|
23
21
|
exports.isRouterInstance = isRouterInstance;
|
|
24
22
|
class Router {
|
|
@@ -27,27 +25,22 @@ class Router {
|
|
|
27
25
|
this['@instanceof'] = Symbol.for('Router');
|
|
28
26
|
this.stack = [];
|
|
29
27
|
options = options || {};
|
|
30
|
-
|
|
31
|
-
this.options
|
|
32
|
-
this.setOption('mountPath', this.options.mountPath);
|
|
28
|
+
this.timeout = options.timeout;
|
|
29
|
+
this.setMountPath(options.mountPath || '/');
|
|
33
30
|
}
|
|
34
31
|
// --------------------------------------------------
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
this.options.mountPath = '/';
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (typeof value === 'string') {
|
|
42
|
-
this.options.mountPath = (0, utils_2.withLeadingSlash)((0, utils_2.withoutTrailingSlash)(`${value}`));
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.options.mountPath = value;
|
|
46
|
-
}
|
|
47
|
-
this.pathMatcher = new path_1.PathMatcher(this.options.mountPath, { end: false });
|
|
32
|
+
setMountPath(value) {
|
|
33
|
+
if (value === '/' || !(0, utils_1.isPath)(value)) {
|
|
34
|
+
this.mountPath = '/';
|
|
48
35
|
return;
|
|
49
36
|
}
|
|
50
|
-
|
|
37
|
+
if (typeof value === 'string') {
|
|
38
|
+
this.mountPath = (0, utils_1.withLeadingSlash)((0, utils_1.withoutTrailingSlash)(`${value}`));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this.mountPath = value;
|
|
42
|
+
}
|
|
43
|
+
this.pathMatcher = new path_1.PathMatcher(this.mountPath, { end: false });
|
|
51
44
|
}
|
|
52
45
|
// --------------------------------------------------
|
|
53
46
|
createListener() {
|
|
@@ -72,9 +65,10 @@ class Router {
|
|
|
72
65
|
dispatch(req, res, meta, done) {
|
|
73
66
|
let index = -1;
|
|
74
67
|
meta = meta || {};
|
|
68
|
+
let allowedMethods = [];
|
|
75
69
|
if (this.isRoot &&
|
|
76
|
-
this.
|
|
77
|
-
(0,
|
|
70
|
+
this.timeout) {
|
|
71
|
+
(0, utils_1.createResponseTimeout)(res, this.timeout, done);
|
|
78
72
|
}
|
|
79
73
|
const fn = (err) => {
|
|
80
74
|
/* istanbul ignore if */
|
|
@@ -90,6 +84,15 @@ class Router {
|
|
|
90
84
|
res.end();
|
|
91
85
|
return;
|
|
92
86
|
}
|
|
87
|
+
if (req.method &&
|
|
88
|
+
req.method.toLowerCase() === constants_1.Method.OPTIONS) {
|
|
89
|
+
const options = allowedMethods
|
|
90
|
+
.map((key) => key.toUpperCase())
|
|
91
|
+
.join(',');
|
|
92
|
+
res.setHeader(constants_1.HeaderName.ALLOW, options);
|
|
93
|
+
(0, helpers_1.send)(res, options);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
93
96
|
res.statusCode = 404;
|
|
94
97
|
res.end();
|
|
95
98
|
};
|
|
@@ -97,16 +100,17 @@ class Router {
|
|
|
97
100
|
if (this.pathMatcher) {
|
|
98
101
|
const output = this.pathMatcher.exec(path);
|
|
99
102
|
if (typeof output !== 'undefined') {
|
|
100
|
-
meta.mountPath = (0,
|
|
103
|
+
meta.mountPath = (0, utils_1.cleanDoubleSlashes)(`${meta.mountPath || ''}/${output.path}`);
|
|
101
104
|
if (path === output.path) {
|
|
102
105
|
path = '/';
|
|
103
106
|
}
|
|
104
107
|
else {
|
|
105
|
-
path = (0,
|
|
108
|
+
path = (0, utils_1.withLeadingSlash)(path.substring(output.path.length));
|
|
106
109
|
}
|
|
107
110
|
meta.params = (0, smob_1.merge)(meta.params || {}, output.params);
|
|
108
111
|
}
|
|
109
112
|
}
|
|
113
|
+
meta.path = path;
|
|
110
114
|
if (!meta.mountPath) {
|
|
111
115
|
meta.mountPath = '/';
|
|
112
116
|
}
|
|
@@ -131,6 +135,9 @@ class Router {
|
|
|
131
135
|
if (req.method &&
|
|
132
136
|
!layer.matchMethod(req.method)) {
|
|
133
137
|
match = false;
|
|
138
|
+
if (req.method.toLowerCase() === constants_1.Method.OPTIONS) {
|
|
139
|
+
allowedMethods = (0, smob_1.mergeArrays)(allowedMethods, layer.getMethods(), true);
|
|
140
|
+
}
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
143
|
}
|
|
@@ -138,16 +145,17 @@ class Router {
|
|
|
138
145
|
fn(err);
|
|
139
146
|
return;
|
|
140
147
|
}
|
|
141
|
-
const layerMeta = Object.assign(
|
|
148
|
+
const layerMeta = Object.assign({}, meta);
|
|
142
149
|
if ((0, layer_1.isLayerInstance)(layer)) {
|
|
143
150
|
const output = layer.exec(path);
|
|
144
151
|
if (output) {
|
|
145
152
|
layerMeta.params = (0, smob_1.merge)(output.params, layerMeta.params || {});
|
|
146
|
-
layerMeta.mountPath = (0,
|
|
153
|
+
layerMeta.mountPath = (0, utils_1.cleanDoubleSlashes)(`${layerMeta.mountPath || ''}/${output.path}`);
|
|
147
154
|
}
|
|
148
155
|
}
|
|
149
156
|
if (err) {
|
|
150
|
-
if ((0, layer_1.isLayerInstance)(layer) &&
|
|
157
|
+
if ((0, layer_1.isLayerInstance)(layer) &&
|
|
158
|
+
layer.isError()) {
|
|
151
159
|
layer.dispatch(req, res, layerMeta, next, err);
|
|
152
160
|
return;
|
|
153
161
|
}
|
|
@@ -175,7 +183,7 @@ class Router {
|
|
|
175
183
|
route(path) {
|
|
176
184
|
if (typeof path === 'string' &&
|
|
177
185
|
path.length > 0) {
|
|
178
|
-
path = (0,
|
|
186
|
+
path = (0, utils_1.withLeadingSlash)(path);
|
|
179
187
|
}
|
|
180
188
|
const index = this.stack.findIndex((item) => (0, route_1.isRouteInstance)(item) && item.path === path);
|
|
181
189
|
if (index !== -1) {
|
|
@@ -210,20 +218,30 @@ class Router {
|
|
|
210
218
|
route.patch(...handlers);
|
|
211
219
|
return this;
|
|
212
220
|
}
|
|
221
|
+
head(path, ...handlers) {
|
|
222
|
+
const route = this.route(path);
|
|
223
|
+
route.head(...handlers);
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
options(path, ...handlers) {
|
|
227
|
+
const route = this.route(path);
|
|
228
|
+
route.options(...handlers);
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
213
231
|
use(...input) {
|
|
214
232
|
/* istanbul ignore next */
|
|
215
233
|
if (input.length === 0) {
|
|
216
234
|
return this;
|
|
217
235
|
}
|
|
218
236
|
let path;
|
|
219
|
-
if ((0,
|
|
237
|
+
if ((0, utils_1.isPath)(input[0])) {
|
|
220
238
|
path = input.shift();
|
|
221
239
|
}
|
|
222
240
|
for (let i = 0; i < input.length; i++) {
|
|
223
241
|
const item = input[i];
|
|
224
242
|
if (isRouterInstance(item)) {
|
|
225
243
|
if (path) {
|
|
226
|
-
item.
|
|
244
|
+
item.setMountPath(path);
|
|
227
245
|
}
|
|
228
246
|
this.stack.push(item);
|
|
229
247
|
continue;
|
|
@@ -234,49 +252,6 @@ class Router {
|
|
|
234
252
|
}
|
|
235
253
|
return this;
|
|
236
254
|
}
|
|
237
|
-
// --------------------------------------------------
|
|
238
|
-
useController(input) {
|
|
239
|
-
let controller;
|
|
240
|
-
if ((0, smob_1.isObject)(input)) {
|
|
241
|
-
controller = input;
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
controller = new input();
|
|
245
|
-
}
|
|
246
|
-
const meta = (0, utils_1.useDecoratorMeta)(controller);
|
|
247
|
-
const router = new Router();
|
|
248
|
-
for (let i = 0; i < meta.middlewares.length; i++) {
|
|
249
|
-
const handler = (0, handler_1.createHandlerForClassType)(meta.middlewares[i]);
|
|
250
|
-
router.use(handler);
|
|
251
|
-
}
|
|
252
|
-
const propertyKeys = Object.keys(meta.methods);
|
|
253
|
-
for (let i = 0; i < propertyKeys.length; i++) {
|
|
254
|
-
const handler = (req, res, next) => {
|
|
255
|
-
const output = controller[propertyKeys[i]].apply(controller, [
|
|
256
|
-
...(0, decorators_1.buildDecoratorMethodArguments)(req, res, next, meta.parameters[propertyKeys[i]]),
|
|
257
|
-
]);
|
|
258
|
-
(0, handler_1.processHandlerExecutionOutput)(res, next, output);
|
|
259
|
-
};
|
|
260
|
-
const method = meta.methods[propertyKeys[i]];
|
|
261
|
-
const handlers = [];
|
|
262
|
-
if (method.middlewares) {
|
|
263
|
-
for (let i = 0; i < method.middlewares.length; i++) {
|
|
264
|
-
handlers.push((0, handler_1.createHandlerForClassType)(method.middlewares[i]));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
router[method.method].apply(router, [
|
|
268
|
-
method.url,
|
|
269
|
-
...handlers,
|
|
270
|
-
handler,
|
|
271
|
-
]);
|
|
272
|
-
}
|
|
273
|
-
this.use(meta.url, router);
|
|
274
|
-
}
|
|
275
|
-
useControllers(input) {
|
|
276
|
-
for (let i = 0; i < input.length; i++) {
|
|
277
|
-
this.useController(input[i]);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
255
|
}
|
|
281
256
|
exports.Router = Router;
|
|
282
257
|
//# sourceMappingURL=module.js.map
|