@midwayjs/koa 3.0.0-beta.1 → 3.0.0-beta.10

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/CHANGELOG.md CHANGED
@@ -3,6 +3,101 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
7
+
8
+
9
+ ### Features
10
+
11
+ * default add session & bodyparser support for koa/express/faas ([#1420](https://github.com/midwayjs/midway/issues/1420)) ([cdaff31](https://github.com/midwayjs/midway/commit/cdaff317c3e862a95494a167995a28280af639bf))
12
+ * implement i18n for validate ([#1426](https://github.com/midwayjs/midway/issues/1426)) ([4c7ed2f](https://github.com/midwayjs/midway/commit/4c7ed2ff2e7ccf10f88f62abad230f92f5e76b97))
13
+
14
+
15
+
16
+
17
+
18
+ # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
19
+
20
+ **Note:** Version bump only for package @midwayjs/koa
21
+
22
+
23
+
24
+
25
+
26
+ # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([b9272e0](https://github.com/midwayjs/midway/commit/b9272e0971003443304b0c53815be31a0061b4bd))
32
+ * passport missing proxy file ([#1405](https://github.com/midwayjs/midway/issues/1405)) ([5c9bdae](https://github.com/midwayjs/midway/commit/5c9bdae8323b41ead72c3d3f867aa11150bb3e78))
33
+
34
+
35
+
36
+
37
+
38
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
39
+
40
+
41
+ ### Bug Fixes
42
+
43
+ * add app.keys ([#1395](https://github.com/midwayjs/midway/issues/1395)) ([c44afc6](https://github.com/midwayjs/midway/commit/c44afc6cc6764a959d1fa7ae04d60099282d156a))
44
+ * middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
45
+
46
+
47
+
48
+
49
+
50
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
51
+
52
+
53
+ ### Bug Fixes
54
+
55
+ * class transformer method missing ([#1387](https://github.com/midwayjs/midway/issues/1387)) ([074e839](https://github.com/midwayjs/midway/commit/074e8393598dc95e2742f735df75a2191c5fe25d))
56
+
57
+
58
+
59
+
60
+
61
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
62
+
63
+ **Note:** Version bump only for package @midwayjs/koa
64
+
65
+
66
+
67
+
68
+
69
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
70
+
71
+
72
+ ### Features
73
+
74
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
75
+ * auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
76
+ * support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
77
+
78
+
79
+
80
+
81
+
82
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
83
+
84
+
85
+ ### Features
86
+
87
+ * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
88
+
89
+
90
+
91
+
92
+
93
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
94
+
95
+ **Note:** Version bump only for package @midwayjs/koa
96
+
97
+
98
+
99
+
100
+
6
101
  # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
7
102
 
8
103
 
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # midway-web for koa
1
+ # midway for koa
2
2
 
3
3
  [![Package Quality](http://npm.packagequality.com/shield/midway-web.svg)](http://packagequality.com/#?package=midway-web)
4
4
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)
5
5
 
6
6
  this is a sub package for midway.
7
7
 
8
- Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)
8
+ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
@@ -0,0 +1,47 @@
1
+ /**
2
+ * koa server options
3
+ */
4
+ export declare const koa: {};
5
+ /**
6
+ * The key that signing cookies. It can contain multiple keys seperated by `,`.
7
+ * @member {String} Config#keys
8
+ */
9
+ export declare const keys = "";
10
+ /**
11
+ * default cookie options
12
+ *
13
+ * @member Config#cookies
14
+ * @property {String} sameSite - SameSite property, defaults is ''
15
+ * @property {Boolean} httpOnly - httpOnly property, defaults is true
16
+ */
17
+ export declare const cookies: {};
18
+ export declare const onerror: {};
19
+ /**
20
+ * @member Config#bodyParser
21
+ * @property {Boolean} enable - enable bodyParser or not, default is true
22
+ * @property {String | RegExp | Function | Array} ignore - won't parse request body when url path hit ignore pattern, can not set `ignore` when `match` presented
23
+ * @property {String | RegExp | Function | Array} match - will parse request body only when url path hit match pattern
24
+ * @property {String} encoding - body's encoding type,default is utf8
25
+ * @property {String} formLimit - limit of the urlencoded body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 1mb
26
+ * @property {String} jsonLimit - limit of the json body, default is 1mb
27
+ * @property {String} textLimit - limit of the text body, default is 1mb
28
+ * @property {Boolean} strict - when set to true, JSON parser will only accept arrays and objects. Default is true
29
+ * @property {Number} queryString.arrayLimit - urlencoded body array's max length, default is 100
30
+ * @property {Number} queryString.depth - urlencoded body object's max depth, default is 5
31
+ * @property {Number} queryString.parameterLimit - urlencoded body maximum parameters, default is 1000
32
+ */
33
+ export declare const bodyParser: {
34
+ enable: boolean;
35
+ encoding: string;
36
+ formLimit: string;
37
+ jsonLimit: string;
38
+ textLimit: string;
39
+ strict: boolean;
40
+ queryString: {
41
+ arrayLimit: number;
42
+ depth: number;
43
+ parameterLimit: number;
44
+ };
45
+ onerror(err: any): never;
46
+ };
47
+ //# sourceMappingURL=config.default.d.ts.map
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bodyParser = exports.onerror = exports.cookies = exports.keys = exports.koa = void 0;
4
+ /**
5
+ * koa server options
6
+ */
7
+ exports.koa = {};
8
+ /**
9
+ * The key that signing cookies. It can contain multiple keys seperated by `,`.
10
+ * @member {String} Config#keys
11
+ */
12
+ exports.keys = '';
13
+ /**
14
+ * default cookie options
15
+ *
16
+ * @member Config#cookies
17
+ * @property {String} sameSite - SameSite property, defaults is ''
18
+ * @property {Boolean} httpOnly - httpOnly property, defaults is true
19
+ */
20
+ exports.cookies = {
21
+ // httpOnly: true | false,
22
+ // sameSite: 'none|lax|strict',
23
+ };
24
+ exports.onerror = {};
25
+ /**
26
+ * @member Config#bodyParser
27
+ * @property {Boolean} enable - enable bodyParser or not, default is true
28
+ * @property {String | RegExp | Function | Array} ignore - won't parse request body when url path hit ignore pattern, can not set `ignore` when `match` presented
29
+ * @property {String | RegExp | Function | Array} match - will parse request body only when url path hit match pattern
30
+ * @property {String} encoding - body's encoding type,default is utf8
31
+ * @property {String} formLimit - limit of the urlencoded body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 1mb
32
+ * @property {String} jsonLimit - limit of the json body, default is 1mb
33
+ * @property {String} textLimit - limit of the text body, default is 1mb
34
+ * @property {Boolean} strict - when set to true, JSON parser will only accept arrays and objects. Default is true
35
+ * @property {Number} queryString.arrayLimit - urlencoded body array's max length, default is 100
36
+ * @property {Number} queryString.depth - urlencoded body object's max depth, default is 5
37
+ * @property {Number} queryString.parameterLimit - urlencoded body maximum parameters, default is 1000
38
+ */
39
+ exports.bodyParser = {
40
+ enable: true,
41
+ encoding: 'utf8',
42
+ formLimit: '1mb',
43
+ jsonLimit: '1mb',
44
+ textLimit: '1mb',
45
+ strict: true,
46
+ // @see https://github.com/hapijs/qs/blob/master/lib/parse.js#L8 for more options
47
+ queryString: {
48
+ arrayLimit: 100,
49
+ depth: 5,
50
+ parameterLimit: 1000,
51
+ },
52
+ onerror(err) {
53
+ err.message += ', check bodyParser config';
54
+ throw err;
55
+ },
56
+ };
57
+ //# sourceMappingURL=config.default.js.map
@@ -1,10 +1,10 @@
1
+ import { MidwayConfigService, MidwayDecoratorService } from '@midwayjs/core';
1
2
  import { MidwayKoaFramework } from './framework';
2
- import { MidwayDecoratorService } from '@midwayjs/core';
3
3
  export declare class KoaConfiguration {
4
- framework: MidwayKoaFramework;
5
4
  decoratorService: MidwayDecoratorService;
5
+ koaFramework: MidwayKoaFramework;
6
+ configService: MidwayConfigService;
6
7
  init(): void;
7
8
  onReady(): Promise<void>;
8
- onServerReady(): Promise<void>;
9
9
  }
10
10
  //# sourceMappingURL=configuration.d.ts.map
@@ -11,27 +11,38 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.KoaConfiguration = void 0;
13
13
  const decorator_1 = require("@midwayjs/decorator");
14
- const framework_1 = require("./framework");
15
14
  const core_1 = require("@midwayjs/core");
15
+ const session = require("@midwayjs/session");
16
+ const framework_1 = require("./framework");
17
+ const bodyParser = require("koa-bodyparser");
18
+ const DefaultConfig = require("./config/config.default");
16
19
  let KoaConfiguration = class KoaConfiguration {
17
20
  init() {
21
+ // register param decorator
18
22
  this.decoratorService.registerParameterHandler(decorator_1.WEB_ROUTER_PARAM_KEY, options => {
19
- return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData)(options.originArgs[0], options.originArgs[1]);
23
+ return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType)(options.originArgs[0], options.originArgs[1]);
20
24
  });
21
25
  }
22
- async onReady() { }
23
- async onServerReady() {
24
- await this.framework.run();
26
+ async onReady() {
27
+ // use bodyparser middleware
28
+ const bodyparserConfig = this.configService.getConfiguration('bodyParser');
29
+ if (bodyparserConfig.enable) {
30
+ this.koaFramework.useMiddleware(bodyParser(bodyparserConfig));
31
+ }
25
32
  }
26
33
  };
34
+ __decorate([
35
+ (0, decorator_1.Inject)(),
36
+ __metadata("design:type", core_1.MidwayDecoratorService)
37
+ ], KoaConfiguration.prototype, "decoratorService", void 0);
27
38
  __decorate([
28
39
  (0, decorator_1.Inject)(),
29
40
  __metadata("design:type", framework_1.MidwayKoaFramework)
30
- ], KoaConfiguration.prototype, "framework", void 0);
41
+ ], KoaConfiguration.prototype, "koaFramework", void 0);
31
42
  __decorate([
32
43
  (0, decorator_1.Inject)(),
33
- __metadata("design:type", core_1.MidwayDecoratorService)
34
- ], KoaConfiguration.prototype, "decoratorService", void 0);
44
+ __metadata("design:type", core_1.MidwayConfigService)
45
+ ], KoaConfiguration.prototype, "configService", void 0);
35
46
  __decorate([
36
47
  (0, decorator_1.Init)(),
37
48
  __metadata("design:type", Function),
@@ -41,6 +52,12 @@ __decorate([
41
52
  KoaConfiguration = __decorate([
42
53
  (0, decorator_1.Configuration)({
43
54
  namespace: 'koa',
55
+ imports: [session],
56
+ importConfigs: [
57
+ {
58
+ default: DefaultConfig,
59
+ },
60
+ ],
44
61
  })
45
62
  ], KoaConfiguration);
46
63
  exports.KoaConfiguration = KoaConfiguration;
@@ -1,10 +1,9 @@
1
1
  /// <reference types="node" />
2
- import { BaseFramework, IMidwayBootstrapOptions, MidwayFrameworkType } from '@midwayjs/core';
3
- import { RouterParamValue } from '@midwayjs/decorator';
2
+ import { BaseFramework, CommonFilterUnion, CommonMiddlewareUnion, IMidwayBootstrapOptions, MidwayFrameworkType, RouterInfo } from '@midwayjs/core';
4
3
  import { IMidwayKoaApplication, IMidwayKoaConfigurationOptions, IMidwayKoaContext } from './interface';
5
- import type { DefaultState, Middleware } from 'koa';
4
+ import type { DefaultState, Middleware, Next } from 'koa';
6
5
  import { Server } from 'net';
7
- export declare class MidwayKoaFramework extends BaseFramework<IMidwayKoaApplication, IMidwayKoaContext, IMidwayKoaConfigurationOptions> {
6
+ export declare class MidwayKoaFramework extends BaseFramework<IMidwayKoaApplication, IMidwayKoaContext, IMidwayKoaConfigurationOptions, Next> {
8
7
  private server;
9
8
  private generator;
10
9
  configure(): IMidwayKoaConfigurationOptions;
@@ -12,11 +11,8 @@ export declare class MidwayKoaFramework extends BaseFramework<IMidwayKoaApplicat
12
11
  loadMidwayController(): Promise<void>;
13
12
  /**
14
13
  * wrap controller string to middleware function
15
- * @param controllerMapping like FooController.index
16
- * @param routeArgsInfo
17
- * @param routerResponseData
18
14
  */
19
- generateController(controllerMapping: string, routeArgsInfo?: RouterParamValue[], routerResponseData?: any[]): Middleware<DefaultState, IMidwayKoaContext>;
15
+ generateController(routeInfo: RouterInfo): Middleware<DefaultState, IMidwayKoaContext>;
20
16
  /**
21
17
  * @deprecated
22
18
  * @param middlewareId
@@ -27,5 +23,7 @@ export declare class MidwayKoaFramework extends BaseFramework<IMidwayKoaApplicat
27
23
  getFrameworkType(): MidwayFrameworkType;
28
24
  getFrameworkName(): string;
29
25
  getServer(): Server;
26
+ useMiddleware(Middleware: CommonMiddlewareUnion<IMidwayKoaContext, Next, unknown>): void;
27
+ useFilter(Filter: CommonFilterUnion<IMidwayKoaContext, Next, unknown>): void;
30
28
  }
31
29
  //# sourceMappingURL=framework.d.ts.map
package/dist/framework.js CHANGED
@@ -8,23 +8,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.MidwayKoaFramework = void 0;
10
10
  const core_1 = require("@midwayjs/core");
11
+ const cookies_1 = require("@midwayjs/cookies");
11
12
  const decorator_1 = require("@midwayjs/decorator");
12
13
  const Router = require("@koa/router");
13
14
  const koa = require("koa");
15
+ const onerror = require("koa-onerror");
16
+ const COOKIES = Symbol('context#cookies');
14
17
  class KoaControllerGenerator extends core_1.WebControllerGenerator {
15
- constructor(app, applicationContext, logger) {
16
- super(applicationContext, core_1.MidwayFrameworkType.WEB_KOA, logger);
18
+ constructor(app) {
19
+ super(app);
17
20
  this.app = app;
18
- this.applicationContext = applicationContext;
19
- this.logger = logger;
20
21
  }
21
22
  createRouter(routerOptions) {
22
23
  const router = new Router(routerOptions);
23
24
  router.prefix(routerOptions.prefix);
24
25
  return router;
25
26
  }
26
- generateController(controllerMapping, routeArgsInfo, routerResponseData) {
27
- return this.generateKoaController(controllerMapping, routeArgsInfo, routerResponseData);
27
+ generateController(routeInfo) {
28
+ return this.generateKoaController(routeInfo);
28
29
  }
29
30
  }
30
31
  let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
@@ -32,33 +33,65 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
32
33
  return this.configService.getConfiguration('koa');
33
34
  }
34
35
  async applicationInitialize(options) {
35
- this.app = new koa();
36
- this.app.use(async (ctx, next) => {
37
- this.app.createAnonymousContext(ctx);
38
- const { result, error } = await (await this.getMiddleware())(ctx, next);
39
- if (error) {
40
- throw error;
41
- }
42
- if (result) {
43
- ctx.body = result;
44
- }
36
+ const appKeys = this.configService.getConfiguration('keys') ||
37
+ this.configurationOptions['keys'];
38
+ if (!appKeys) {
39
+ throw new core_1.MidwayConfigMissingError('config.keys');
40
+ }
41
+ const cookieOptions = this.configService.getConfiguration('cookies');
42
+ this.app = new koa({
43
+ keys: [].concat(appKeys),
45
44
  });
46
- this.generator = new KoaControllerGenerator(this.app, this.applicationContext, this.appLogger);
47
- this.defineApplicationProperties({
48
- generateController: (controllerMapping) => {
49
- return this.generateController(controllerMapping);
50
- },
51
- /**
52
- * @deprecated
53
- * @param middlewareId
54
- */
55
- generateMiddleware: async (middlewareId) => {
56
- return this.generateMiddleware(middlewareId);
45
+ Object.defineProperty(this.app.context, 'cookies', {
46
+ get() {
47
+ if (!this[COOKIES]) {
48
+ this[COOKIES] = new cookies_1.Cookies(this, this.app.keys, cookieOptions);
49
+ }
50
+ return this[COOKIES];
57
51
  },
52
+ enumerable: true,
58
53
  });
54
+ const onerrorConfig = this.configService.getConfiguration('onerror');
55
+ onerror(this.app, onerrorConfig);
56
+ const midwayRootMiddleware = async (ctx, next) => {
57
+ this.app.createAnonymousContext(ctx);
58
+ await (await this.applyMiddleware())(ctx, next);
59
+ };
60
+ this.app.use(midwayRootMiddleware);
61
+ this.generator = new KoaControllerGenerator(this.app);
62
+ this.defineApplicationProperties();
59
63
  // hack use method
60
64
  this.app.originUse = this.app.use;
61
65
  this.app.use = this.app.useMiddleware;
66
+ }
67
+ async loadMidwayController() {
68
+ await this.generator.loadMidwayController(this.configurationOptions.globalPrefix, newRouter => {
69
+ var _a;
70
+ const dispatchFn = newRouter.middleware();
71
+ dispatchFn._name = `midwayController(${((_a = newRouter === null || newRouter === void 0 ? void 0 : newRouter.opts) === null || _a === void 0 ? void 0 : _a.prefix) || '/'})`;
72
+ this.app.use(dispatchFn);
73
+ });
74
+ }
75
+ /**
76
+ * wrap controller string to middleware function
77
+ */
78
+ generateController(routeInfo) {
79
+ return this.generator.generateKoaController(routeInfo);
80
+ }
81
+ /**
82
+ * @deprecated
83
+ * @param middlewareId
84
+ */
85
+ async generateMiddleware(middlewareId) {
86
+ const mwIns = await this.getApplicationContext().getAsync(middlewareId);
87
+ return mwIns.resolve();
88
+ }
89
+ async run() {
90
+ var _a;
91
+ // load controller
92
+ await this.loadMidwayController();
93
+ // restore use method
94
+ this.app.use = this.app.originUse;
62
95
  // https config
63
96
  if (this.configurationOptions.key && this.configurationOptions.cert) {
64
97
  this.configurationOptions.key = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.key);
@@ -81,36 +114,9 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
81
114
  }
82
115
  // register httpServer to applicationContext
83
116
  this.applicationContext.registerObject(core_1.HTTP_SERVER_KEY, this.server);
84
- }
85
- async loadMidwayController() {
86
- await this.generator.loadMidwayController(newRouter => {
87
- this.app.use(newRouter.middleware());
88
- });
89
- }
90
- /**
91
- * wrap controller string to middleware function
92
- * @param controllerMapping like FooController.index
93
- * @param routeArgsInfo
94
- * @param routerResponseData
95
- */
96
- generateController(controllerMapping, routeArgsInfo, routerResponseData) {
97
- return this.generator.generateKoaController(controllerMapping, routeArgsInfo, routerResponseData);
98
- }
99
- /**
100
- * @deprecated
101
- * @param middlewareId
102
- */
103
- async generateMiddleware(middlewareId) {
104
- const mwIns = await this.getApplicationContext().getAsync(middlewareId);
105
- return mwIns.resolve();
106
- }
107
- async run() {
108
- // load controller
109
- await this.loadMidwayController();
110
- // restore use method
111
- this.app.use = this.app.originUse;
112
117
  // set port and listen server
113
- if (this.configurationOptions.port) {
118
+ const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : this.configurationOptions.port;
119
+ if (customPort) {
114
120
  new Promise(resolve => {
115
121
  const args = [this.configurationOptions.port];
116
122
  if (this.configurationOptions.hostname) {
@@ -120,6 +126,7 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
120
126
  resolve();
121
127
  });
122
128
  this.server.listen(...args);
129
+ process.env.MIDWAY_HTTP_PORT = String(customPort);
123
130
  });
124
131
  }
125
132
  }
@@ -135,6 +142,12 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
135
142
  getServer() {
136
143
  return this.server;
137
144
  }
145
+ useMiddleware(Middleware) {
146
+ this.middlewareManager.insertLast(Middleware);
147
+ }
148
+ useFilter(Filter) {
149
+ this.filterManager.useFilter(Filter);
150
+ }
138
151
  };
139
152
  MidwayKoaFramework = __decorate([
140
153
  (0, decorator_1.Framework)()
@@ -1,8 +1,11 @@
1
+ /// <reference types="koa-session" />
1
2
  /// <reference types="node" />
2
3
  import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
3
4
  import * as koa from 'koa';
4
5
  import { Context as KoaContext, DefaultState, Middleware, Next } from 'koa';
5
6
  import { RouterParamValue } from '@midwayjs/decorator';
7
+ import * as bodyParser from 'koa-bodyparser';
8
+ import { CookieSetOptions } from '@midwayjs/cookies';
6
9
  export declare type IMidwayKoaContext = IMidwayContext<KoaContext>;
7
10
  export declare type IMidwayKoaApplication = IMidwayApplication<IMidwayKoaContext, koa<DefaultState, IMidwayKoaContext> & {
8
11
  generateController(controllerMapping: string, routeArgsInfo?: RouterParamValue[], routerResponseData?: any[]): Middleware<DefaultState, IMidwayKoaContext>;
@@ -12,11 +15,16 @@ export declare type IMidwayKoaApplication = IMidwayApplication<IMidwayKoaContext
12
15
  */
13
16
  generateMiddleware(middlewareId: string): Promise<Middleware<DefaultState, IMidwayKoaContext>>;
14
17
  }>;
18
+ /**
19
+ * @deprecated use NextFunction definition
20
+ */
15
21
  export declare type IMidwayKoaNext = Next;
16
- export interface IMidwayKoaApplicationPlus<CTX extends IMidwayContext> extends IMidwayApplication<CTX> {
17
- use(...args: any[]): any;
18
- }
22
+ export declare type NextFunction = Next;
19
23
  export interface IMidwayKoaConfigurationOptions extends IConfigurationOptions {
24
+ /**
25
+ * cookies sign keys
26
+ */
27
+ keys?: string[];
20
28
  /**
21
29
  * application http port
22
30
  */
@@ -41,6 +49,10 @@ export interface IMidwayKoaConfigurationOptions extends IConfigurationOptions {
41
49
  * http2 support
42
50
  */
43
51
  http2?: boolean;
52
+ /**
53
+ * http global prefix
54
+ */
55
+ globalPrefix?: string;
44
56
  }
45
57
  export declare type MiddlewareParamArray = Array<Middleware<DefaultState, IMidwayKoaContext>>;
46
58
  export interface IWebMiddleware {
@@ -49,4 +61,23 @@ export interface IWebMiddleware {
49
61
  export declare type Application = IMidwayKoaApplication;
50
62
  export interface Context extends IMidwayKoaContext {
51
63
  }
64
+ declare module '@midwayjs/core/dist/interface' {
65
+ interface MidwayConfig {
66
+ keys?: string | string[];
67
+ koa?: IMidwayKoaConfigurationOptions;
68
+ cookies?: CookieSetOptions;
69
+ /**
70
+ * onerror middleware options
71
+ */
72
+ onerror?: {
73
+ text?: (err: Error, ctx: IMidwayKoaContext) => void;
74
+ json?: (err: Error, ctx: IMidwayKoaContext) => void;
75
+ html?: (err: Error, ctx: IMidwayKoaContext) => void;
76
+ redirect?: string;
77
+ template?: string;
78
+ accepts?: (...args: any[]) => any;
79
+ };
80
+ bodyParser?: bodyParser.Options;
81
+ }
82
+ }
52
83
  //# sourceMappingURL=interface.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/koa",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.10",
4
4
  "description": "Midway Web Framework for KOA",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -23,20 +23,22 @@
23
23
  ],
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@midwayjs/decorator": "^3.0.0-beta.1",
27
- "@midwayjs/mock": "^3.0.0-beta.1",
28
- "@midwayjs/validate": "^3.0.0-beta.1",
26
+ "@midwayjs/decorator": "^3.0.0-beta.10",
27
+ "@midwayjs/logger": "^3.0.0-beta.10",
28
+ "@midwayjs/mock": "^3.0.0-beta.10",
29
29
  "@types/koa": "^2.11.4",
30
+ "@types/koa-bodyparser": "^4.3.4",
30
31
  "@types/koa-router": "^7.4.1",
31
- "fs-extra": "^8.0.1",
32
- "koa-bodyparser": "^4.3.0",
33
- "koa-qs": "^3.0.0"
32
+ "fs-extra": "^8.0.1"
34
33
  },
35
34
  "dependencies": {
36
35
  "@koa/router": "^10.0.0",
37
- "@midwayjs/core": "^3.0.0-beta.1",
38
- "@midwayjs/logger": "^3.0.0-beta.1",
39
- "koa": "^2.13.0"
36
+ "@midwayjs/cookies": "^1.0.1",
37
+ "@midwayjs/core": "^3.0.0-beta.10",
38
+ "@midwayjs/session": "^3.0.0-beta.10",
39
+ "koa": "^2.13.4",
40
+ "koa-bodyparser": "^4.3.0",
41
+ "koa-onerror": "^4.1.0"
40
42
  },
41
43
  "author": "Harry Chen <czy88840616@gmail.com>",
42
44
  "repository": {
@@ -46,5 +48,5 @@
46
48
  "engines": {
47
49
  "node": ">=12"
48
50
  },
49
- "gitHead": "72e4d20c678e65a5440c4e9a6d3b70046daa497c"
51
+ "gitHead": "153870f2e2dd6b17673ec7591e49224a6bd51b36"
50
52
  }