@midwayjs/http-proxy 3.20.5 → 4.0.0-beta.1

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.
@@ -24,6 +24,7 @@ let HttpProxyConfiguration = class HttpProxyConfiguration {
24
24
  }
25
25
  }
26
26
  };
27
+ exports.HttpProxyConfiguration = HttpProxyConfiguration;
27
28
  __decorate([
28
29
  (0, core_1.Inject)(),
29
30
  __metadata("design:type", core_1.MidwayApplicationManager)
@@ -32,7 +33,7 @@ __decorate([
32
33
  (0, core_1.Config)('httpProxy'),
33
34
  __metadata("design:type", Object)
34
35
  ], HttpProxyConfiguration.prototype, "httpProxy", void 0);
35
- HttpProxyConfiguration = __decorate([
36
+ exports.HttpProxyConfiguration = HttpProxyConfiguration = __decorate([
36
37
  (0, core_1.Configuration)({
37
38
  namespace: 'http-proxy',
38
39
  importConfigs: [
@@ -42,5 +43,4 @@ HttpProxyConfiguration = __decorate([
42
43
  ],
43
44
  })
44
45
  ], HttpProxyConfiguration);
45
- exports.HttpProxyConfiguration = HttpProxyConfiguration;
46
46
  //# sourceMappingURL=configuration.js.map
@@ -1,9 +1,9 @@
1
1
  /// <reference types="node" />
2
- import { IMiddleware, IMidwayLogger, IMidwayApplication } from '@midwayjs/core';
2
+ import { IMiddleware, ILogger, IMidwayApplication } from '@midwayjs/core';
3
3
  import { HttpProxyConfig } from './interface';
4
4
  export declare class HttpProxyMiddleware implements IMiddleware<any, any> {
5
5
  httpProxy: HttpProxyConfig;
6
- logger: IMidwayLogger;
6
+ logger: ILogger;
7
7
  resolve(app: IMidwayApplication): (req: any, res: any, next: any) => Promise<any>;
8
8
  execProxy(ctx: any, req: any, res: any, next: any, isServerless: any): Promise<any>;
9
9
  getProxyList(url: any): undefined | {
@@ -22,14 +22,12 @@ let HttpProxyMiddleware = class HttpProxyMiddleware {
22
22
  else {
23
23
  const isServerless = app.getNamespace() === 'faas';
24
24
  return async (ctx, next) => {
25
- var _a;
26
- const req = ((_a = ctx.request) === null || _a === void 0 ? void 0 : _a.req) || ctx.request;
25
+ const req = ctx.request?.req || ctx.request;
27
26
  return this.execProxy(ctx, req, ctx, next, isServerless);
28
27
  };
29
28
  }
30
29
  }
31
30
  async execProxy(ctx, req, res, next, isServerless) {
32
- var _a, _b, _c;
33
31
  const proxyInfo = this.getProxyList(ctx.url);
34
32
  if (!proxyInfo) {
35
33
  return next();
@@ -37,7 +35,7 @@ let HttpProxyMiddleware = class HttpProxyMiddleware {
37
35
  const { proxy, url } = proxyInfo;
38
36
  const reqHeaders = {};
39
37
  for (const key of Object.keys(req.headers)) {
40
- if (((_a = proxy.ignoreHeaders) === null || _a === void 0 ? void 0 : _a[key]) || ctx.header[key] === undefined) {
38
+ if (proxy.ignoreHeaders?.[key] || ctx.header[key] === undefined) {
41
39
  continue;
42
40
  }
43
41
  reqHeaders[key.toLowerCase()] = ctx.header[key];
@@ -60,7 +58,7 @@ let HttpProxyMiddleware = class HttpProxyMiddleware {
60
58
  timeout: this.httpProxy.proxyTimeout || 0,
61
59
  };
62
60
  if (method === 'POST' || method === 'PUT') {
63
- reqOptions.data = (_b = req.body) !== null && _b !== void 0 ? _b : (_c = ctx.request) === null || _c === void 0 ? void 0 : _c.body;
61
+ reqOptions.data = req.body ?? ctx.request?.body;
64
62
  if (req.headers['content-type'] === 'application/x-www-form-urlencoded' &&
65
63
  typeof reqOptions.data !== 'string') {
66
64
  reqOptions.data = Object.keys(reqOptions.data)
@@ -147,6 +145,7 @@ let HttpProxyMiddleware = class HttpProxyMiddleware {
147
145
  return 'http-proxy';
148
146
  }
149
147
  };
148
+ exports.HttpProxyMiddleware = HttpProxyMiddleware;
150
149
  __decorate([
151
150
  (0, core_1.Config)('httpProxy'),
152
151
  __metadata("design:type", Object)
@@ -155,8 +154,7 @@ __decorate([
155
154
  (0, core_1.Logger)(),
156
155
  __metadata("design:type", Object)
157
156
  ], HttpProxyMiddleware.prototype, "logger", void 0);
158
- HttpProxyMiddleware = __decorate([
157
+ exports.HttpProxyMiddleware = HttpProxyMiddleware = __decorate([
159
158
  (0, core_1.Middleware)()
160
159
  ], HttpProxyMiddleware);
161
- exports.HttpProxyMiddleware = HttpProxyMiddleware;
162
160
  //# sourceMappingURL=middleware.js.map
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@midwayjs/http-proxy",
3
- "version": "3.20.5",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Midway Component for http proxy",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
10
- "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
9
+ "test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
10
+ "cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
11
11
  "ci": "npm run test"
12
12
  },
13
13
  "keywords": [
@@ -29,13 +29,13 @@
29
29
  "axios": "1.8.4"
30
30
  },
31
31
  "devDependencies": {
32
- "@midwayjs/core": "^3.20.4",
33
- "@midwayjs/express": "^3.20.4",
34
- "@midwayjs/faas": "^3.20.4",
35
- "@midwayjs/koa": "^3.20.5",
36
- "@midwayjs/mock": "^3.20.4",
37
- "@midwayjs/serverless-app": "^3.20.4",
38
- "@midwayjs/web": "^3.20.4"
32
+ "@midwayjs/core": "^4.0.0-beta.1",
33
+ "@midwayjs/express": "^4.0.0-beta.1",
34
+ "@midwayjs/faas": "^4.0.0-beta.1",
35
+ "@midwayjs/koa": "^4.0.0-beta.1",
36
+ "@midwayjs/mock": "^4.0.0-beta.1",
37
+ "@midwayjs/web": "^4.0.0-beta.1",
38
+ "nock": "13.5.5"
39
39
  },
40
- "gitHead": "7ce57281bd3ef5d18dc50b47ff9bffb8a27c071e"
40
+ "gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
41
41
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2013 - Now midwayjs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.