@wooksjs/http-proxy 0.4.11 → 0.4.12
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/index.cjs +0 -4
- package/dist/index.d.ts +17 -18
- package/dist/index.mjs +0 -4
- package/package.json +11 -3
package/dist/index.cjs
CHANGED
|
@@ -97,7 +97,6 @@ function useProxy() {
|
|
|
97
97
|
const targetUrl = new URL(target);
|
|
98
98
|
const path = targetUrl.pathname || '/';
|
|
99
99
|
const url = new URL(path, targetUrl.origin).toString() + targetUrl.search;
|
|
100
|
-
// preparing request headers and cookies
|
|
101
100
|
const modifiedHeaders = { ...req.headers, host: targetUrl.hostname };
|
|
102
101
|
const headers = opts?.reqHeaders
|
|
103
102
|
? applyProxyControls(new HeadersIterable(modifiedHeaders), opts?.reqHeaders, reqHeadersToBlock)
|
|
@@ -111,7 +110,6 @@ function useProxy() {
|
|
|
111
110
|
.join('; ');
|
|
112
111
|
}
|
|
113
112
|
const method = opts?.method || req.method;
|
|
114
|
-
// actual request
|
|
115
113
|
if (opts?.debug) {
|
|
116
114
|
logger.info(`${'[32m'}${req.method} ${req.url}${'[33m'} → ${'[36m'}${method} ${url}${'[33m'}`);
|
|
117
115
|
logger.info('[33m' + 'headers:', JSON.stringify(headers, null, ' '), '[39m');
|
|
@@ -123,13 +121,11 @@ function useProxy() {
|
|
|
123
121
|
: req,
|
|
124
122
|
headers: headers,
|
|
125
123
|
});
|
|
126
|
-
// preparing response
|
|
127
124
|
status.value = resp.status;
|
|
128
125
|
if (opts?.debug) {
|
|
129
126
|
logger.info(`${resp.status} ${'[32m'}${req.method} ${req.url}${'[33m'} → ${'[36m'}${method} ${url}${'[33m'}`);
|
|
130
127
|
logger.info(`${'[33m'}response headers:${'[39m'}`);
|
|
131
128
|
}
|
|
132
|
-
// preparing response headers
|
|
133
129
|
const resHeaders = opts?.resHeaders
|
|
134
130
|
? applyProxyControls(resp.headers.entries(), opts?.resHeaders, resHeadersToBlock)
|
|
135
131
|
: null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
overwrite?: Record<string, string> | ((data: Record<string, string>) => Record<string, string>);
|
|
3
|
-
allow?: (string | RegExp)[] | '*';
|
|
4
|
-
block?: (string | RegExp)[] | '*';
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export { }
|
|
1
|
+
interface TWooksProxyControls {
|
|
2
|
+
overwrite?: Record<string, string> | ((data: Record<string, string>) => Record<string, string>);
|
|
3
|
+
allow?: (string | RegExp)[] | '*';
|
|
4
|
+
block?: (string | RegExp)[] | '*';
|
|
5
|
+
}
|
|
6
|
+
interface TWooksProxyOptions {
|
|
7
|
+
method?: string;
|
|
8
|
+
reqHeaders?: TWooksProxyControls;
|
|
9
|
+
reqCookies?: TWooksProxyControls;
|
|
10
|
+
resHeaders?: TWooksProxyControls;
|
|
11
|
+
resCookies?: TWooksProxyControls;
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare function useProxy(): (target: string, opts?: TWooksProxyOptions) => Promise<Response>;
|
|
16
|
+
|
|
17
|
+
export { type TWooksProxyControls, type TWooksProxyOptions, useProxy };
|
package/dist/index.mjs
CHANGED
|
@@ -95,7 +95,6 @@ function useProxy() {
|
|
|
95
95
|
const targetUrl = new URL(target);
|
|
96
96
|
const path = targetUrl.pathname || '/';
|
|
97
97
|
const url = new URL(path, targetUrl.origin).toString() + targetUrl.search;
|
|
98
|
-
// preparing request headers and cookies
|
|
99
98
|
const modifiedHeaders = { ...req.headers, host: targetUrl.hostname };
|
|
100
99
|
const headers = opts?.reqHeaders
|
|
101
100
|
? applyProxyControls(new HeadersIterable(modifiedHeaders), opts?.reqHeaders, reqHeadersToBlock)
|
|
@@ -109,7 +108,6 @@ function useProxy() {
|
|
|
109
108
|
.join('; ');
|
|
110
109
|
}
|
|
111
110
|
const method = opts?.method || req.method;
|
|
112
|
-
// actual request
|
|
113
111
|
if (opts?.debug) {
|
|
114
112
|
logger.info(`${'[32m'}${req.method} ${req.url}${'[33m'} → ${'[36m'}${method} ${url}${'[33m'}`);
|
|
115
113
|
logger.info('[33m' + 'headers:', JSON.stringify(headers, null, ' '), '[39m');
|
|
@@ -121,13 +119,11 @@ function useProxy() {
|
|
|
121
119
|
: req,
|
|
122
120
|
headers: headers,
|
|
123
121
|
});
|
|
124
|
-
// preparing response
|
|
125
122
|
status.value = resp.status;
|
|
126
123
|
if (opts?.debug) {
|
|
127
124
|
logger.info(`${resp.status} ${'[32m'}${req.method} ${req.url}${'[33m'} → ${'[36m'}${method} ${url}${'[33m'}`);
|
|
128
125
|
logger.info(`${'[33m'}response headers:${'[39m'}`);
|
|
129
126
|
}
|
|
130
|
-
// preparing response headers
|
|
131
127
|
const resHeaders = opts?.resHeaders
|
|
132
128
|
? applyProxyControls(resp.headers.entries(), opts?.resHeaders, resHeadersToBlock)
|
|
133
129
|
: null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/http-proxy",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.12",
|
|
4
4
|
"description": "Proxy Wooks composable",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
|
+
"exports": {
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
".": {
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
11
19
|
"repository": {
|
|
12
20
|
"type": "git",
|
|
13
21
|
"url": "git+https://github.com/wooksjs/wooksjs.git",
|
|
@@ -31,8 +39,8 @@
|
|
|
31
39
|
"url": "https://github.com/wooksjs/wooksjs/issues"
|
|
32
40
|
},
|
|
33
41
|
"peerDependencies": {
|
|
34
|
-
"@wooksjs/event-http": "0.4.
|
|
35
|
-
"@wooksjs/event-core": "0.4.
|
|
42
|
+
"@wooksjs/event-http": "0.4.12",
|
|
43
|
+
"@wooksjs/event-core": "0.4.12"
|
|
36
44
|
},
|
|
37
45
|
"dependencies": {
|
|
38
46
|
"node-fetch-native": "^1.0.1"
|