@midwayjs/koa 3.11.15 → 3.12.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/dist/framework.js CHANGED
@@ -63,6 +63,28 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
63
63
  this.state = value;
64
64
  },
65
65
  });
66
+ Object.defineProperty(this.app.context, 'forward', {
67
+ get() {
68
+ return async function (url) {
69
+ const routerService = this.requestContext.get(core_1.MidwayWebRouterService);
70
+ const matchedUrlRouteInfo = await routerService.getMatchedRouterInfo(url, this.method);
71
+ if (matchedUrlRouteInfo) {
72
+ if (matchedUrlRouteInfo.controllerClz) {
73
+ // normal class controller router
74
+ const controllerInstance = await this.requestContext.getAsync(matchedUrlRouteInfo.controllerClz);
75
+ return controllerInstance[matchedUrlRouteInfo.method](this);
76
+ }
77
+ else if (typeof matchedUrlRouteInfo.method === 'function') {
78
+ // dynamic router
79
+ return matchedUrlRouteInfo.method(this);
80
+ }
81
+ }
82
+ else {
83
+ throw new core_1.httpError.NotFoundError(`Forward url ${url} Not Found`);
84
+ }
85
+ };
86
+ },
87
+ });
66
88
  const onerrorConfig = this.configService.getConfiguration('onerror');
67
89
  (0, onerror_1.setupOnError)(this.app, onerrorConfig, this.logger);
68
90
  // not found middleware
package/index.d.ts CHANGED
@@ -40,5 +40,6 @@ declare module 'koa' {
40
40
  interface Context {
41
41
  cookies: Cookies;
42
42
  app: Application;
43
+ forward: (url: string) => void;
43
44
  }
44
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/koa",
3
- "version": "3.11.15",
3
+ "version": "3.12.0",
4
4
  "description": "Midway Web Framework for KOA",
5
5
  "main": "dist/index",
6
6
  "typings": "index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
27
  "@midwayjs/logger": "^2.15.0",
28
- "@midwayjs/mock": "^3.11.15",
28
+ "@midwayjs/mock": "^3.12.0",
29
29
  "@types/koa": "2.13.6",
30
30
  "@types/koa-router": "7.4.4",
31
31
  "fs-extra": "11.1.1"
@@ -33,8 +33,8 @@
33
33
  "dependencies": {
34
34
  "@koa/router": "^11.0.0",
35
35
  "@midwayjs/cookies": "^1.0.2",
36
- "@midwayjs/core": "^3.11.15",
37
- "@midwayjs/session": "^3.11.15",
36
+ "@midwayjs/core": "^3.12.0",
37
+ "@midwayjs/session": "^3.12.0",
38
38
  "koa": "2.14.1",
39
39
  "koa-bodyparser": "4.4.1"
40
40
  },
@@ -46,5 +46,5 @@
46
46
  "engines": {
47
47
  "node": ">=12"
48
48
  },
49
- "gitHead": "a4054247f3b9f4fc8ba51684c002606d849e0bd3"
49
+ "gitHead": "0e9a08cd078c4c4dedfa753a8c1025806cc0b0a2"
50
50
  }