koatty 3.3.8 → 3.4.8

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.
Files changed (51) hide show
  1. package/.eslintrc.js +2 -1
  2. package/.vscode/settings.json +3 -0
  3. package/CHANGELOG.md +8 -0
  4. package/LICENSE +1 -1
  5. package/README.md +5 -0
  6. package/babel.config.js +0 -5
  7. package/demo/static/test.css +3 -0
  8. package/demo/tsconfig.json +66 -0
  9. package/dist/config/config.d.ts +1 -1
  10. package/dist/config/config.js +1 -1
  11. package/dist/config/config.js.map +1 -1
  12. package/dist/config/middleware.d.ts +4 -6
  13. package/dist/config/middleware.js +7 -16
  14. package/dist/config/middleware.js.map +1 -1
  15. package/dist/config/router.js +20 -16
  16. package/dist/config/router.js.map +1 -1
  17. package/dist/controller/BaseController.d.ts +0 -97
  18. package/dist/controller/BaseController.js +2 -146
  19. package/dist/controller/BaseController.js.map +1 -1
  20. package/dist/controller/HttpController.d.ts +131 -0
  21. package/dist/controller/HttpController.js +215 -0
  22. package/dist/controller/HttpController.js.map +1 -0
  23. package/dist/core/Bootstrap.d.ts +19 -0
  24. package/dist/core/Bootstrap.js +63 -15
  25. package/dist/core/Bootstrap.js.map +1 -1
  26. package/dist/core/Component.d.ts +2 -11
  27. package/dist/core/Component.js.map +1 -1
  28. package/dist/core/Loader.d.ts +13 -36
  29. package/dist/core/Loader.js +47 -77
  30. package/dist/core/Loader.js.map +1 -1
  31. package/dist/index.d.ts +3 -1
  32. package/dist/index.js +4 -3
  33. package/dist/index.js.map +1 -1
  34. package/dist/middleware/TraceMiddleware.d.ts +11 -0
  35. package/dist/middleware/TraceMiddleware.js +22 -0
  36. package/dist/middleware/TraceMiddleware.js.map +1 -0
  37. package/dist/service/BaseService.js +1 -2
  38. package/dist/service/BaseService.js.map +1 -1
  39. package/dist/util/Logger.d.ts +21 -1
  40. package/dist/util/Logger.js +32 -3
  41. package/dist/util/Logger.js.map +1 -1
  42. package/jest.config.js +19 -1
  43. package/jest_html_reporters.html +1 -1
  44. package/package.json +29 -24
  45. package/tsconfig.json +1 -1
  46. package/dist/core/Router.d.ts +0 -15
  47. package/dist/core/Router.js +0 -19
  48. package/dist/core/Router.js.map +0 -1
  49. package/dist/core/Serve.d.ts +0 -8
  50. package/dist/core/Serve.js +0 -62
  51. package/dist/core/Serve.js.map +0 -1
package/.eslintrc.js CHANGED
@@ -22,12 +22,13 @@ module.exports = {
22
22
  },
23
23
  rules: {
24
24
  "@typescript-eslint/no-explicit-any": "off",
25
- "@typescript-eslint/no-require-imports": "off",
25
+ // "@typescript-eslint/no-require-imports": "off",
26
26
  "@typescript-eslint/no-var-requires": "off",
27
27
  "@typescript-eslint/member-ordering": "off",
28
28
  "@typescript-eslint/consistent-type-assertions": "off",
29
29
  "@typescript-eslint/no-param-reassign": "off",
30
30
  "@typescript-eslint/no-empty-function": "off",
31
+ "@typescript-eslint/no-empty-interface": "off",
31
32
  "@typescript-eslint/explicit-module-boundary-types": "off",
32
33
  "@typescript-eslint/ban-types": ["error",
33
34
  {
@@ -0,0 +1,3 @@
1
+ {
2
+ "debug.javascript.unmapMissingSources": true
3
+ }
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [3.4.8](https://github.com/thinkkoa/koatty/compare/v3.4.4...v3.4.8) (2021-11-25)
6
+
7
+ ### [3.4.6](https://github.com/thinkkoa/koatty/compare/v3.4.4...v3.4.6) (2021-11-25)
8
+
9
+ ### [3.4.4](https://github.com/thinkkoa/koatty/compare/v3.4.2...v3.4.4) (2021-11-20)
10
+
11
+ ### [3.4.2](https://github.com/thinkkoa/koatty/compare/v3.3.6...v3.4.2) (2021-11-19)
12
+
5
13
  ### [3.3.6](https://github.com/thinkkoa/koatty/compare/v3.2.12...v3.3.6) (2021-07-13)
6
14
 
7
15
  ### [3.3.4](https://github.com/thinkkoa/koatty/compare/v3.3.3...v3.3.4) (2021-07-07)
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  BSD 3-Clause License
2
2
 
3
- Copyright (c) 2020, ThinkKoa
3
+ Copyright (c) 2020, Koatty
4
4
  All rights reserved.
5
5
 
6
6
  Redistribution and use in source and binary forms, with or without
package/README.md CHANGED
@@ -6,6 +6,11 @@ Use Typescript's decorator implement IOC and AOP.
6
6
 
7
7
  [![Version npm](https://img.shields.io/npm/v/koatty.svg?style=flat-square)](https://www.npmjs.com/package/koatty)[![npm Downloads](https://img.shields.io/npm/dm/koatty.svg?style=flat-square)](https://npmcharts.com/compare/koatty?minimal=true)
8
8
 
9
+ ## New
10
+
11
+ * HTTP、HTTPS、HTTP2 .
12
+ * gRPC server.
13
+ * WebSocket server. (unstable)
9
14
  ## Documentation
10
15
 
11
16
  [koatty_doc_CN](https://koatty.github.io/koatty_doc/) (In progress💪)
package/babel.config.js CHANGED
@@ -1,11 +1,6 @@
1
1
  /*
2
2
  * @Description : babel配置
3
3
  * @usage : 用于jest执行用例
4
- * @Date : 2020-10-19 23:08:40
5
- * @Author : fankerwang<fankerwang@tencent.com>
6
- * @LastEditors : fankerwang<fankerwang@tencent.com>
7
- * @LastEditTime : 2021-05-21 20:27:11
8
- * @FilePath : /tkoatty/babel.config.js
9
4
  */
10
5
 
11
6
  module.exports = {
@@ -0,0 +1,3 @@
1
+ .css {
2
+ color: #000;
3
+ }
@@ -0,0 +1,66 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Basic Options */
4
+ "target": "es2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */,
5
+ "module": "commonjs" /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
6
+ "lib": [
7
+ "es2019"
8
+ ]
9
+ /* Specify library files to be included in the compilation: */ ,
10
+ // "allowJs": true /* Allow javascript files to be compiled. */,
11
+ // "checkJs": true, /* Report errors in .js files. */
12
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13
+ "declaration": true /* Generates corresponding '.d.ts' file. */,
14
+ "sourceMap": true /* Generates corresponding '.map' file. */,
15
+ // "outFile": "./", /* Concatenate and emit output to single file. */
16
+ "outDir": "./dist/" /* Redirect output structure to the directory. */,
17
+ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
18
+ "removeComments": true /* Do not emit comments to output. */,
19
+ // "noEmit": true /* Do not emit outputs. */,
20
+ "importHelpers": true /* Import emit helpers from 'tslib'. */,
21
+ "downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
22
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
23
+ /* Strict Type-Checking Options */
24
+ "stripInternal": true /* Enable all strict type-checking options. */,
25
+ "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
26
+ // "strictNullChecks": true, /* Enable strict null checks. */
27
+ "noImplicitThis": false /* Raise error on 'this' expressions with an implied 'any' type. */,
28
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
29
+ "pretty": true, /* pretty source file. */
30
+ /* Additional Checks */
31
+ // "noUnusedLocals": true, /* Report errors on unused locals. */
32
+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
33
+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
34
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
35
+ /* Module Resolution Options */
36
+ "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
37
+ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
38
+ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
39
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
40
+ "typeRoots": [
41
+ "node_modules/@types"
42
+ // "./typings/*"
43
+ ] /* List of folders to include type definitions from. */,
44
+ "types": [
45
+ "node"
46
+ ] /* Type declaration files to be included in compilation. */,
47
+ "allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
48
+ "resolveJsonModule": true,
49
+ "esModuleInterop": true,
50
+ /* Source Map Options */
51
+ // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
52
+ // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
53
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
54
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
55
+ /* Experimental Options */
56
+ "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
57
+ "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
58
+ },
59
+ "exclude": [
60
+ "node_modules"
61
+ ],
62
+ "include": [
63
+ "src",
64
+ "src/**/*.json"
65
+ ]
66
+ }
@@ -1,7 +1,7 @@
1
1
  declare const _default: {
2
2
  app_port: number;
3
3
  app_host: string;
4
- serve_mod: string;
4
+ protocol: string;
5
5
  open_trace: boolean;
6
6
  http_timeout: number;
7
7
  key_file: string;
@@ -10,7 +10,7 @@ exports.default = {
10
10
  /*app config*/
11
11
  app_port: 3000,
12
12
  app_host: "",
13
- serve_mod: "http",
13
+ protocol: "http",
14
14
  open_trace: false,
15
15
  http_timeout: 10,
16
16
  key_file: "",
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,kBAAe;IACX,cAAc;IACd,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,MAAM;IACjB,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE,EAAE;IAChB,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,OAAO;IAEjB,mGAAmG;IACnG,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,KAAK;IACjB,gBAAgB,EAAE,MAAM;IACxB,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,OAAO,EAAE,qBAAqB;CAEpE,CAAC"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,kBAAe;IACX,cAAc;IACd,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE,EAAE;IAChB,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,OAAO;IAEjB,mGAAmG;IACnG,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,KAAK;IACjB,gBAAgB,EAAE,MAAM;IACxB,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,OAAO,EAAE,qBAAqB;CAEpE,CAAC"}
@@ -1,12 +1,10 @@
1
- /**
2
- * @ author: richen
3
- * @ copyright: Copyright (c) - <richenlin(at)gmail.com>
4
- * @ license: BSD (3-Clause)
5
- * @ version: 2020-04-30 14:52:34
6
- */
7
1
  declare const _default: {
8
2
  list: any[];
9
3
  config: {
4
+ TraceMiddleware: {
5
+ HeaderName: string;
6
+ IdFactory: (<T extends ArrayLike<number>>(options: import("uuid").V4Options, buffer: T, offset?: number) => T) & ((options?: import("uuid").V4Options) => string);
7
+ };
10
8
  PayloadMiddleware: {
11
9
  extTypes: {
12
10
  json: string[];
@@ -1,30 +1,21 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
2
3
  /**
3
4
  * @ author: richen
4
5
  * @ copyright: Copyright (c) - <richenlin(at)gmail.com>
5
6
  * @ license: BSD (3-Clause)
6
7
  * @ version: 2020-04-30 14:52:34
7
8
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
+ const uuid_1 = require("uuid");
9
10
  exports.default = {
10
11
  // List of loaded middleware(except for the middleware loaded by default),
11
12
  // executed in the order of elements
12
13
  list: [],
13
14
  config: {
14
- // The default is off, if you need to enable it, modify it to
15
- // "StaticMiddleware": {
16
- // dir: '/static', // resource path
17
- // prefix: '', // the url prefix you wish to add, default to ''
18
- // alias: {}, // object map of aliases. See below
19
- // gzip: true, // when request's accept-encoding include gzip, files will compressed by gzip.
20
- // usePrecompiledGzip: false, // try use gzip files, loaded from disk, like nginx gzip_static
21
- // buffer: false, // store the files in memory instead of streaming from the filesystem on each request
22
- // filter: [], // (function | array) - filter files at init dir, for example - skip non build (source) files. If array set - allow only listed files
23
- // maxAge: 3600 * 24 * 7, // cache control max age for the files, 0 by default.
24
- // preload: false, // caches the assets on initialization or not, default to true. always work together with options.dynamic.
25
- // cache: false // dynamic load file which not cached on initialization.
26
- // },
27
- // "StaticMiddleware": false,
15
+ "TraceMiddleware": {
16
+ HeaderName: 'X-Request-Id',
17
+ IdFactory: uuid_1.v4,
18
+ },
28
19
  "PayloadMiddleware": {
29
20
  "extTypes": {
30
21
  "json": ['application/json'],
@@ -37,7 +28,7 @@ exports.default = {
37
28
  "encoding": 'utf-8',
38
29
  "multiples": true,
39
30
  "keepExtensions": true
40
- }
31
+ },
41
32
  }
42
33
  };
43
34
  //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/config/middleware.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,kBAAe;IACX,2EAA2E;IAC3E,oCAAoC;IACpC,IAAI,EAAE,EAAE;IACR,MAAM,EAAE;QACJ,8DAA8D;QAC9D,wBAAwB;QACxB,uCAAuC;QACvC,mEAAmE;QACnE,qDAAqD;QACrD,iGAAiG;QACjG,iGAAiG;QACjG,2GAA2G;QAC3G,wJAAwJ;QACxJ,mFAAmF;QACnF,iIAAiI;QACjI,4EAA4E;QAC5E,KAAK;QACL,6BAA6B;QAC7B,mBAAmB,EAAE;YACjB,UAAU,EAAE;gBACR,MAAM,EAAE,CAAC,kBAAkB,CAAC;gBAC5B,MAAM,EAAE,CAAC,mCAAmC,CAAC;gBAC7C,MAAM,EAAE,CAAC,YAAY,CAAC;gBACtB,WAAW,EAAE,CAAC,qBAAqB,CAAC;gBACpC,KAAK,EAAE,CAAC,UAAU,CAAC;aACtB;YACD,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,OAAO;YACnB,WAAW,EAAE,IAAI;YACjB,gBAAgB,EAAE,IAAI;SACzB;KACJ;CACJ,CAAC"}
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/config/middleware.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,+BAAoC;AAEpC,kBAAe;IACX,2EAA2E;IAC3E,oCAAoC;IACpC,IAAI,EAAE,EAAE;IACR,MAAM,EAAE;QACJ,iBAAiB,EAAE;YACf,UAAU,EAAE,cAAc;YAC1B,SAAS,EAAE,SAAM;SACpB;QACD,mBAAmB,EAAE;YACjB,UAAU,EAAE;gBACR,MAAM,EAAE,CAAC,kBAAkB,CAAC;gBAC5B,MAAM,EAAE,CAAC,mCAAmC,CAAC;gBAC7C,MAAM,EAAE,CAAC,YAAY,CAAC;gBACtB,WAAW,EAAE,CAAC,qBAAqB,CAAC;gBACpC,KAAK,EAAE,CAAC,UAAU,CAAC;aACtB;YACD,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,OAAO;YACnB,WAAW,EAAE,IAAI;YACjB,gBAAgB,EAAE,IAAI;SACzB;KACJ;CACJ,CAAC"}
@@ -8,21 +8,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  */
9
9
  exports.default = {
10
10
  // prefix: string;
11
- // /**
12
- // * Methods which should be supported by the router.
13
- // */
14
- // methods ?: string[];
15
- // routerPath ?: string;
16
- // /**
17
- // * Whether or not routing should be case-sensitive.
18
- // */
19
- // sensitive ?: boolean;
20
- // /**
21
- // * Whether or not routes should matched strictly.
22
- // *
23
- // * If strict matching is enabled, the trailing slash is taken into
24
- // * account when matching routes.
25
- // */
26
- // strict ?: boolean;
11
+ /**
12
+ * Methods which should be supported by the router.
13
+ */
14
+ // methods?: string[];
15
+ // routerPath?: string;
16
+ /**
17
+ * Whether or not routing should be case-sensitive.
18
+ */
19
+ // sensitive?: boolean;
20
+ /**
21
+ * Whether or not routes should matched strictly.
22
+ *
23
+ * If strict matching is enabled, the trailing slash is taken into
24
+ * account when matching routes.
25
+ */
26
+ // strict?: boolean;
27
+ /**
28
+ * Other extended configuration
29
+ */
30
+ // ext?: any;
27
31
  };
28
32
  //# sourceMappingURL=router.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/config/router.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,kBAAe;AACX,kBAAkB;AAClB,MAAM;AACN,sDAAsD;AACtD,MAAM;AACN,uBAAuB;AACvB,wBAAwB;AACxB,MAAM;AACN,sDAAsD;AACtD,MAAM;AACN,wBAAwB;AACxB,MAAM;AACN,oDAAoD;AACpD,KAAK;AACL,qEAAqE;AACrE,mCAAmC;AACnC,MAAM;AACN,qBAAqB;CACxB,CAAC"}
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/config/router.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,kBAAe;AACX,kBAAkB;AAElB;;GAEG;AACH,sBAAsB;AAEtB,uBAAuB;AAEvB;;GAEG;AACH,uBAAuB;AAEvB;;;;;GAKG;AACH,oBAAoB;AAEpB;;GAEG;AACH,aAAa;CAChB,CAAC"}
@@ -26,103 +26,6 @@ export declare class BaseController implements IController {
26
26
  * @memberof BaseController
27
27
  */
28
28
  protected init(): void;
29
- /**
30
- * Whether it is a GET request
31
- *
32
- * @public
33
- * @returns {boolean}
34
- * @memberof BaseController
35
- */
36
- isGet(): boolean;
37
- /**
38
- * Whether it is a POST request
39
- *
40
- * @public
41
- * @returns {boolean}
42
- * @memberof BaseController
43
- */
44
- isPost(): boolean;
45
- /**
46
- * Determines whether the METHOD request is specified
47
- *
48
- * @public
49
- * @param {string} method
50
- * @returns {boolean}
51
- * @memberof BaseController
52
- */
53
- isMethod(method: string): boolean;
54
- /**
55
- * Get/Set headers.
56
- *
57
- * @public
58
- * @param {string} [name]
59
- * @param {*} [value]
60
- * @returns {*}
61
- * @memberof BaseController
62
- */
63
- header(name?: string, value?: any): any;
64
- /**
65
- * Get POST/GET parameters, the POST value is priority.
66
- *
67
- * @param {string} [name]
68
- * @returns
69
- * @memberof BaseController
70
- */
71
- param(name?: string): Promise<any>;
72
- /**
73
- * Set response content-type
74
- *
75
- * @public
76
- * @param {string} contentType
77
- * @param {(string | boolean)} [encoding]
78
- * @returns {string}
79
- * @memberof BaseController
80
- */
81
- type(contentType: string, encoding?: string | boolean): string;
82
- /**
83
- * set cache-control and expires header
84
- *
85
- * @public
86
- * @param {number} [timeout=30]
87
- * @returns {void}
88
- * @memberof BaseController
89
- */
90
- expires(timeout?: number): void;
91
- /**
92
- * Url redirect
93
- *
94
- * @param {string} urls
95
- * @param {string} [alt]
96
- * @returns {void}
97
- * @memberof BaseController
98
- */
99
- redirect(urls: string, alt?: string): void;
100
- /**
101
- * Block access
102
- *
103
- * @param {number} [code=403]
104
- * @returns {Promise<any>}
105
- * @memberof BaseController
106
- */
107
- deny(code?: number): Promise<any>;
108
- /**
109
- * Set response Body content
110
- *
111
- * @param {*} data
112
- * @param {string} [contentType]
113
- * @param {string} [encoding]
114
- * @returns {Promise<any>}
115
- * @memberof BaseController
116
- */
117
- body(data: any, contentType?: string, encoding?: string): Promise<any>;
118
- /**
119
- * Respond to json formatted content
120
- *
121
- * @param {*} data
122
- * @returns {Promise<any>}
123
- * @memberof BaseController
124
- */
125
- json(data: any): Promise<any>;
126
29
  /**
127
30
  * Format api interface data format
128
31
  *
@@ -53,150 +53,6 @@ class BaseController {
53
53
  // public __after(): Promise<any> {
54
54
  // return Promise.resolve();
55
55
  // }
56
- /**
57
- * Whether it is a GET request
58
- *
59
- * @public
60
- * @returns {boolean}
61
- * @memberof BaseController
62
- */
63
- isGet() {
64
- return this.ctx.method === "GET";
65
- }
66
- /**
67
- * Whether it is a POST request
68
- *
69
- * @public
70
- * @returns {boolean}
71
- * @memberof BaseController
72
- */
73
- isPost() {
74
- return this.ctx.method === "POST";
75
- }
76
- /**
77
- * Determines whether the METHOD request is specified
78
- *
79
- * @public
80
- * @param {string} method
81
- * @returns {boolean}
82
- * @memberof BaseController
83
- */
84
- isMethod(method) {
85
- return this.ctx.method === method.toUpperCase();
86
- }
87
- /**
88
- * Get/Set headers.
89
- *
90
- * @public
91
- * @param {string} [name]
92
- * @param {*} [value]
93
- * @returns {*}
94
- * @memberof BaseController
95
- */
96
- header(name, value) {
97
- if (name === undefined) {
98
- return this.ctx.headers;
99
- }
100
- if (value === undefined) {
101
- return this.ctx.get(name);
102
- }
103
- return this.ctx.set(name, value);
104
- }
105
- /**
106
- * Get POST/GET parameters, the POST value is priority.
107
- *
108
- * @param {string} [name]
109
- * @returns
110
- * @memberof BaseController
111
- */
112
- param(name) {
113
- return this.ctx.bodyParser().then((body) => {
114
- const getParams = this.ctx.queryParser() || {};
115
- const postParams = (body.post ? body.post : body) || {};
116
- if (name !== undefined) {
117
- return postParams[name] === undefined ? getParams[name] : postParams[name];
118
- }
119
- return { ...getParams, ...postParams };
120
- });
121
- }
122
- /**
123
- * Set response content-type
124
- *
125
- * @public
126
- * @param {string} contentType
127
- * @param {(string | boolean)} [encoding]
128
- * @returns {string}
129
- * @memberof BaseController
130
- */
131
- type(contentType, encoding) {
132
- if (encoding !== false && !contentType.includes("charset")) {
133
- contentType = `${contentType}; charset=${encoding || this.app.config("encoding")}`;
134
- }
135
- this.ctx.type = contentType;
136
- return contentType;
137
- }
138
- /**
139
- * set cache-control and expires header
140
- *
141
- * @public
142
- * @param {number} [timeout=30]
143
- * @returns {void}
144
- * @memberof BaseController
145
- */
146
- expires(timeout = 30) {
147
- timeout = Helper_1.Helper.toNumber(timeout) * 1000;
148
- const date = new Date(Date.now() + timeout);
149
- this.ctx.set("Cache-Control", `max-age=${timeout}`);
150
- return this.ctx.set("Expires", date.toUTCString());
151
- }
152
- /**
153
- * Url redirect
154
- *
155
- * @param {string} urls
156
- * @param {string} [alt]
157
- * @returns {void}
158
- * @memberof BaseController
159
- */
160
- redirect(urls, alt) {
161
- return this.ctx.redirect(urls, alt);
162
- }
163
- /**
164
- * Block access
165
- *
166
- * @param {number} [code=403]
167
- * @returns {Promise<any>}
168
- * @memberof BaseController
169
- */
170
- deny(code = 403) {
171
- return this.ctx.throw(code);
172
- }
173
- /**
174
- * Set response Body content
175
- *
176
- * @param {*} data
177
- * @param {string} [contentType]
178
- * @param {string} [encoding]
179
- * @returns {Promise<any>}
180
- * @memberof BaseController
181
- */
182
- body(data, contentType, encoding) {
183
- contentType = contentType || "text/plain";
184
- encoding = encoding || this.app.config("encoding") || "utf-8";
185
- this.type(contentType, encoding);
186
- this.ctx.body = data;
187
- // return this.app.prevent();
188
- return null;
189
- }
190
- /**
191
- * Respond to json formatted content
192
- *
193
- * @param {*} data
194
- * @returns {Promise<any>}
195
- * @memberof BaseController
196
- */
197
- json(data) {
198
- return this.body(data, "application/json");
199
- }
200
56
  /**
201
57
  * Format api interface data format
202
58
  *
@@ -238,7 +94,7 @@ class BaseController {
238
94
  */
239
95
  ok(msg, data, code = 0) {
240
96
  const obj = this.formatApiData(msg, data, code);
241
- return this.json(obj);
97
+ return Promise.resolve(obj);
242
98
  }
243
99
  /**
244
100
  * Response to normalize json format content for fail
@@ -251,7 +107,7 @@ class BaseController {
251
107
  */
252
108
  fail(msg, data, code = 1) {
253
109
  const obj = this.formatApiData(msg, data, code);
254
- return this.json(obj);
110
+ return Promise.resolve(obj);
255
111
  }
256
112
  }
257
113
  exports.BaseController = BaseController;
@@ -1 +1 @@
1
- {"version":3,"file":"BaseController.js","sourceRoot":"","sources":["../../src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