@modern-js/create-request 1.1.3-beta.0 → 1.1.3-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.
@@ -31,7 +31,7 @@ export const createRequest = (path, method, port, fetch = originFetch) => {
31
31
  pathToRegexp(path, keys);
32
32
 
33
33
  const sender = async (...args) => {
34
- const fetcher = realRequest || fetch;
34
+ const fetcher = realRequest || originFetch;
35
35
  const payload = typeof args[args.length - 1] === 'object' ? args[args.length - 1] : {};
36
36
  payload.params = payload.params || {};
37
37
  keys.forEach((key, index) => {
@@ -46,7 +46,9 @@ export const createRequest = (path, method, port, fetch = nodeFetch) => {
46
46
  let body; // BFF 内网请求需要携带 SSR 请求中的 cookie 和 traceId, 如果有压测头,则添加压测头
47
47
 
48
48
  for (const key of realAllowedHeaders) {
49
- headers[key] = webRequestHeaders[key];
49
+ if (typeof webRequestHeaders[key] !== 'undefined') {
50
+ headers[key] = webRequestHeaders[key];
51
+ }
50
52
  }
51
53
 
52
54
  if (payload.data) {
@@ -71,7 +73,7 @@ export const createRequest = (path, method, port, fetch = nodeFetch) => {
71
73
  }
72
74
 
73
75
  const url = `http://localhost:${port}${finalPath}`;
74
- const fetcher = realRequest || fetch;
76
+ const fetcher = realRequest || originFetch;
75
77
  return fetcher(url, {
76
78
  method,
77
79
  body,
@@ -43,7 +43,7 @@ const createRequest = (path, method, port, fetch = originFetch) => {
43
43
  (0, _pathToRegexp.pathToRegexp)(path, keys);
44
44
 
45
45
  const sender = async (...args) => {
46
- const fetcher = realRequest || fetch;
46
+ const fetcher = realRequest || originFetch;
47
47
  const payload = typeof args[args.length - 1] === 'object' ? args[args.length - 1] : {};
48
48
  payload.params = payload.params || {};
49
49
  keys.forEach((key, index) => {
@@ -63,7 +63,9 @@ const createRequest = (path, method, port, fetch = _nodeFetch.default) => {
63
63
  let body; // BFF 内网请求需要携带 SSR 请求中的 cookie 和 traceId, 如果有压测头,则添加压测头
64
64
 
65
65
  for (const key of realAllowedHeaders) {
66
- headers[key] = webRequestHeaders[key];
66
+ if (typeof webRequestHeaders[key] !== 'undefined') {
67
+ headers[key] = webRequestHeaders[key];
68
+ }
67
69
  }
68
70
 
69
71
  if (payload.data) {
@@ -88,7 +90,7 @@ const createRequest = (path, method, port, fetch = _nodeFetch.default) => {
88
90
  }
89
91
 
90
92
  const url = `http://localhost:${port}${finalPath}`;
91
- const fetcher = realRequest || fetch;
93
+ const fetcher = realRequest || originFetch;
92
94
  return fetcher(url, {
93
95
  method,
94
96
  body,
@@ -60,7 +60,7 @@ export var createRequest = function createRequest(path, method, port) {
60
60
  args[_key] = _args[_key];
61
61
  }
62
62
 
63
- fetcher = realRequest || fetch;
63
+ fetcher = realRequest || originFetch;
64
64
  payload = _typeof(args[args.length - 1]) === 'object' ? args[args.length - 1] : {};
65
65
  payload.params = payload.params || {};
66
66
  keys.forEach(function (key, index) {
@@ -64,7 +64,10 @@ export var createRequest = function createRequest(path, method, port) {
64
64
  try {
65
65
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
66
66
  var key = _step.value;
67
- headers[key] = webRequestHeaders[key];
67
+
68
+ if (typeof webRequestHeaders[key] !== 'undefined') {
69
+ headers[key] = webRequestHeaders[key];
70
+ }
68
71
  }
69
72
  } catch (err) {
70
73
  _iterator.e(err);
@@ -94,7 +97,7 @@ export var createRequest = function createRequest(path, method, port) {
94
97
  }
95
98
 
96
99
  var url = "http://localhost:".concat(port).concat(finalPath);
97
- var fetcher = realRequest || fetch;
100
+ var fetcher = realRequest || originFetch;
98
101
  return fetcher(url, {
99
102
  method: method,
100
103
  body: body,
@@ -9,12 +9,12 @@ export declare type BFFRequestPayload = {
9
9
  headers?: Record<string, any>;
10
10
  cookies?: Record<string, any>;
11
11
  };
12
- export declare type Fetch = typeof nodeFetch | typeof fetch;
12
+ export declare type Fetch = typeof fetch | typeof nodeFetch;
13
13
  export declare type Sender = ((...args: any[]) => Promise<any>) & {
14
14
  fetch?: Fetch;
15
15
  };
16
16
  export declare type RequestCreator = (path: string, method: string, port: number, fetch?: Fetch, headerWhiteList?: string[]) => Sender;
17
- export declare type IOptions<F = typeof fetch> = {
17
+ export declare type IOptions<F = Fetch> = {
18
18
  request?: F;
19
19
  interceptor?: (request: F) => F;
20
20
  allowedHeaders?: string[];
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.3-beta.0",
14
+ "version": "1.1.3-beta.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",