@midwayjs/cross-domain 3.10.7 → 3.10.9

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.
@@ -13,12 +13,14 @@ exports.CrossDomainConfiguration = void 0;
13
13
  const core_1 = require("@midwayjs/core");
14
14
  const DefaultConfig = require("./config/config.default");
15
15
  const cors_1 = require("./middleware/cors");
16
+ const jsonp_1 = require("./middleware/jsonp");
16
17
  let CrossDomainConfiguration = class CrossDomainConfiguration {
17
18
  async onReady() {
18
19
  this.applicationManager
19
20
  .getApplications(['koa', 'faas', 'express', 'egg'])
20
21
  .forEach(app => {
21
22
  app.useMiddleware(cors_1.CorsMiddleware);
23
+ app.useMiddleware(jsonp_1.ContextJSONPMiddleware);
22
24
  });
23
25
  }
24
26
  };
@@ -9,4 +9,9 @@ export declare class JSONPMiddleware implements IMiddleware<any, any> {
9
9
  compatibleMiddleware(context: any, next: any): Promise<any>;
10
10
  static getName(): string;
11
11
  }
12
+ export declare class ContextJSONPMiddleware implements IMiddleware<any, any> {
13
+ resolve(app: any): (req: any, res: any, next: any) => Promise<any>;
14
+ compatibleMiddleware(context: any, next: any): Promise<any>;
15
+ static getName(): string;
16
+ }
12
17
  //# sourceMappingURL=jsonp.d.ts.map
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.JSONPMiddleware = exports.JSONPFilter = void 0;
12
+ exports.ContextJSONPMiddleware = exports.JSONPMiddleware = exports.JSONPFilter = void 0;
13
13
  const core_1 = require("@midwayjs/core");
14
14
  const jsonp_1 = require("../jsonp");
15
15
  const error_1 = require("../error");
@@ -64,4 +64,30 @@ JSONPMiddleware = __decorate([
64
64
  (0, core_1.Middleware)()
65
65
  ], JSONPMiddleware);
66
66
  exports.JSONPMiddleware = JSONPMiddleware;
67
+ let ContextJSONPMiddleware = class ContextJSONPMiddleware {
68
+ resolve(app) {
69
+ if (app.getFrameworkType() === core_1.MidwayFrameworkType.WEB_EXPRESS) {
70
+ return async (req, res, next) => {
71
+ return this.compatibleMiddleware(req, next);
72
+ };
73
+ }
74
+ else {
75
+ return async (ctx, next) => {
76
+ return this.compatibleMiddleware(ctx, next);
77
+ };
78
+ }
79
+ }
80
+ async compatibleMiddleware(context, next) {
81
+ const jsonpService = await context.requestContext.getAsync(jsonp_1.JSONPService);
82
+ context.jsonp = jsonpService.jsonp.bind(jsonpService);
83
+ return await next();
84
+ }
85
+ static getName() {
86
+ return 'context-jsonp';
87
+ }
88
+ };
89
+ ContextJSONPMiddleware = __decorate([
90
+ (0, core_1.Middleware)()
91
+ ], ContextJSONPMiddleware);
92
+ exports.ContextJSONPMiddleware = ContextJSONPMiddleware;
67
93
  //# sourceMappingURL=jsonp.js.map
package/index.d.ts CHANGED
@@ -7,3 +7,27 @@ declare module '@midwayjs/core/dist/interface' {
7
7
  jsonp?: Partial<JSONPOptions>;
8
8
  }
9
9
  }
10
+
11
+ declare module '@midwayjs/koa/dist/interface' {
12
+ interface Context {
13
+ jsonp: (body: any, config?: JSONPOptions) => string;
14
+ }
15
+ }
16
+
17
+ declare module '@midwayjs/web/dist/interface' {
18
+ interface Context {
19
+ jsonp: (body: any, config?: JSONPOptions) => string;
20
+ }
21
+ }
22
+
23
+ declare module '@midwayjs/faas/dist/interface' {
24
+ interface Context {
25
+ jsonp: (body: any, config?: JSONPOptions) => string;
26
+ }
27
+ }
28
+
29
+ declare module '@midwayjs/express/dist/interface' {
30
+ interface Context {
31
+ jsonp: (body: any, config?: JSONPOptions) => string;
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/cross-domain",
3
- "version": "3.10.7",
3
+ "version": "3.10.9",
4
4
  "description": "Midway Component for Cross Domain",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -25,13 +25,13 @@
25
25
  "vary": "^1.1.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@midwayjs/core": "^3.10.7",
29
- "@midwayjs/express": "^3.10.7",
30
- "@midwayjs/faas": "^3.10.7",
31
- "@midwayjs/koa": "^3.10.7",
32
- "@midwayjs/mock": "^3.10.7",
33
- "@midwayjs/serverless-app": "^3.10.7",
34
- "@midwayjs/web": "^3.10.7"
28
+ "@midwayjs/core": "^3.10.9",
29
+ "@midwayjs/express": "^3.10.9",
30
+ "@midwayjs/faas": "^3.10.9",
31
+ "@midwayjs/koa": "^3.10.9",
32
+ "@midwayjs/mock": "^3.10.9",
33
+ "@midwayjs/serverless-app": "^3.10.9",
34
+ "@midwayjs/web": "^3.10.9"
35
35
  },
36
- "gitHead": "63bb5a11574dc6cae158c5de51fa5c5d5d482545"
36
+ "gitHead": "4c8368283bd5ff3c14c23080838e2567c3e9a749"
37
37
  }