@midwayjs/http-proxy 3.19.0 → 4.0.0-alpha.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.
- package/dist/configuration.js +2 -2
- package/dist/middleware.d.ts +2 -2
- package/dist/middleware.js +5 -7
- package/package.json +12 -12
package/dist/configuration.js
CHANGED
|
@@ -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
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { IMiddleware,
|
|
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:
|
|
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 | {
|
package/dist/middleware.js
CHANGED
|
@@ -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
|
-
|
|
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 (
|
|
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 =
|
|
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
|
+
"version": "4.0.0-alpha.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
|
|
10
|
-
"cov": "node
|
|
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": [
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"axios": "1.7.
|
|
29
|
+
"axios": "1.7.9"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@midwayjs/core": "^
|
|
33
|
-
"@midwayjs/express": "^
|
|
34
|
-
"@midwayjs/faas": "^
|
|
35
|
-
"@midwayjs/koa": "^
|
|
36
|
-
"@midwayjs/mock": "^
|
|
37
|
-
"@midwayjs/
|
|
38
|
-
"
|
|
32
|
+
"@midwayjs/core": "^4.0.0-alpha.1",
|
|
33
|
+
"@midwayjs/express": "^4.0.0-alpha.1",
|
|
34
|
+
"@midwayjs/faas": "^4.0.0-alpha.1",
|
|
35
|
+
"@midwayjs/koa": "^4.0.0-alpha.1",
|
|
36
|
+
"@midwayjs/mock": "^4.0.0-alpha.1",
|
|
37
|
+
"@midwayjs/web": "^4.0.0-alpha.1",
|
|
38
|
+
"nock": "13.5.5"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
|
|
41
41
|
}
|