@miqro/core 1.5.20 → 1.5.21
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/proxy.js +5 -3
- package/dist/proxy.js.map +1 -1
- package/package.json +4 -4
- package/src/proxy.func.test.js +65 -0
- package/src/proxy.ts +8 -4
- package/src/proxy.unit.test.js +3 -1
package/dist/proxy.js
CHANGED
|
@@ -21,13 +21,12 @@ class ProxyRouter extends router_1.Router {
|
|
|
21
21
|
const nUrl = new url_1.URL(this.proxyURL.toString());
|
|
22
22
|
nUrl.pathname = nUrl.pathname + relative;
|
|
23
23
|
const url = nUrl.toString();
|
|
24
|
-
ctx.logger.info("proxy to %s", url.toString());
|
|
25
24
|
const headers = {
|
|
26
25
|
...ctx.headers
|
|
27
26
|
};
|
|
28
27
|
delete headers["connection"];
|
|
29
28
|
delete headers["keep-alive"];
|
|
30
|
-
const
|
|
29
|
+
const requestArgs = {
|
|
31
30
|
url: url.toString(),
|
|
32
31
|
disableThrow: true,
|
|
33
32
|
rejectUnauthorized: this.rejectUnauthorized,
|
|
@@ -35,7 +34,10 @@ class ProxyRouter extends router_1.Router {
|
|
|
35
34
|
method: ctx.method,
|
|
36
35
|
headers,
|
|
37
36
|
data: ctx.method !== "GET" ? ctx.buffer : undefined
|
|
38
|
-
}
|
|
37
|
+
};
|
|
38
|
+
ctx.logger.info("proxy to %s", url.toString());
|
|
39
|
+
ctx.logger.debug("proxy with %o", requestArgs);
|
|
40
|
+
const response = await (0, request_1.request)(requestArgs);
|
|
39
41
|
const responseHeaders = {
|
|
40
42
|
...response.headers
|
|
41
43
|
};
|
package/dist/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":";;;AACA,4CAAuD;AAC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|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@miqro/test": "0.2.1",
|
|
20
|
-
"@miqro/test-http": "0.0.
|
|
20
|
+
"@miqro/test-http": "0.0.5",
|
|
21
21
|
"@types/node": "17.0.23",
|
|
22
22
|
"typescript": "4.6.4",
|
|
23
23
|
"@types/cookie": "0.4.1",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"npm": ">=6.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@miqro/request": "^0.0.
|
|
32
|
-
"@miqro/parser": "^0.1.
|
|
31
|
+
"@miqro/request": "^0.0.10",
|
|
32
|
+
"@miqro/parser": "^0.1.4",
|
|
33
33
|
"cookie": "0.5.0",
|
|
34
34
|
"uuid": "8.3.2"
|
|
35
35
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const {fake, requireMock} = require("@miqro/test");
|
|
2
|
+
const {resolve} = require("path");
|
|
3
|
+
const {strictEqual} = require("assert");
|
|
4
|
+
const {distPath, basePath} = require("./setup-test.js");
|
|
5
|
+
const {TestHelper} = require("@miqro/test-http");
|
|
6
|
+
const {request} = require("@miqro/request");
|
|
7
|
+
|
|
8
|
+
const testFilePath = resolve(distPath, "proxy.js");
|
|
9
|
+
|
|
10
|
+
describe("proxy functional tests2", () => {
|
|
11
|
+
describe("simple post", () => {
|
|
12
|
+
setTestTimeout(10000);
|
|
13
|
+
const lib = requireMock(distPath, {});
|
|
14
|
+
let server;
|
|
15
|
+
const port = 9595;
|
|
16
|
+
before(async () => {
|
|
17
|
+
const serverApp = new lib.App();
|
|
18
|
+
serverApp.use(lib.JSONParser());
|
|
19
|
+
serverApp.use(async (ctx) => {
|
|
20
|
+
ctx.logger.info("serverApp hit with %o", ctx.body);
|
|
21
|
+
});
|
|
22
|
+
serverApp.post("/api/login", async (ctx) => {
|
|
23
|
+
ctx.logger.info("login hit with %o", ctx.body);
|
|
24
|
+
await ctx.json(ctx.body);
|
|
25
|
+
});
|
|
26
|
+
server = await serverApp.listen(9595);
|
|
27
|
+
|
|
28
|
+
await (async function testServerApp() {
|
|
29
|
+
const response = await request({
|
|
30
|
+
url: `http://localhost:${port}/api/login`,
|
|
31
|
+
method: "POST",
|
|
32
|
+
data: {
|
|
33
|
+
testUP: "1"
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
strictEqual(response.status, 200);
|
|
37
|
+
})()
|
|
38
|
+
});
|
|
39
|
+
after(async () => {
|
|
40
|
+
await server.close();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("happy path", async () => {
|
|
44
|
+
const proxyApp = new lib.App();
|
|
45
|
+
proxyApp.use(lib.JSONParser());
|
|
46
|
+
proxyApp.use(async (ctx) => {
|
|
47
|
+
ctx.logger.info("proxy hit with %o", ctx.body);
|
|
48
|
+
});
|
|
49
|
+
proxyApp.use(lib.Proxy({
|
|
50
|
+
url: "http://localhost:" + port
|
|
51
|
+
}), "/proxy");
|
|
52
|
+
const response = await TestHelper(proxyApp, {
|
|
53
|
+
disableThrow: true,
|
|
54
|
+
url: `/proxy/api/login`,
|
|
55
|
+
method: "POST",
|
|
56
|
+
data: {
|
|
57
|
+
userName: "hello",
|
|
58
|
+
password: "world"
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
strictEqual(response.status, 200);
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
})
|
|
65
|
+
});
|
package/src/proxy.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Context} from "./common";
|
|
2
|
-
import {request} from "@miqro/request";
|
|
2
|
+
import {request, RequestOptions} from "@miqro/request";
|
|
3
3
|
import {Router, RouterOptions} from "./router";
|
|
4
4
|
import {normalizePath, PathPartToken} from "./common/tokenize-match";
|
|
5
5
|
import {URL} from "url";
|
|
@@ -32,7 +32,6 @@ class ProxyRouter extends Router {
|
|
|
32
32
|
const nUrl = new URL(this.proxyURL.toString());
|
|
33
33
|
nUrl.pathname = nUrl.pathname + relative;
|
|
34
34
|
const url = nUrl.toString();
|
|
35
|
-
ctx.logger.info("proxy to %s", url.toString());
|
|
36
35
|
|
|
37
36
|
const headers = {
|
|
38
37
|
...ctx.headers
|
|
@@ -41,7 +40,7 @@ class ProxyRouter extends Router {
|
|
|
41
40
|
delete headers["connection"];
|
|
42
41
|
delete headers["keep-alive"];
|
|
43
42
|
|
|
44
|
-
const
|
|
43
|
+
const requestArgs: RequestOptions = {
|
|
45
44
|
url: url.toString(),
|
|
46
45
|
disableThrow: true,
|
|
47
46
|
rejectUnauthorized: this.rejectUnauthorized,
|
|
@@ -49,7 +48,12 @@ class ProxyRouter extends Router {
|
|
|
49
48
|
method: ctx.method,
|
|
50
49
|
headers,
|
|
51
50
|
data: ctx.method !== "GET" ? ctx.buffer : undefined
|
|
52
|
-
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
ctx.logger.info("proxy to %s", url.toString());
|
|
54
|
+
ctx.logger.debug("proxy with %o", requestArgs);
|
|
55
|
+
|
|
56
|
+
const response = await request(requestArgs);
|
|
53
57
|
|
|
54
58
|
const responseHeaders = {
|
|
55
59
|
...response.headers
|
package/src/proxy.unit.test.js
CHANGED