@modern-js/prod-server 2.9.0 → 2.9.1-alpha.0

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.
Files changed (120) hide show
  1. package/dist/cjs/server/index.js +8 -6
  2. package/dist/esm/server/index.js +71 -18
  3. package/dist/esm-node/server/index.js +9 -6
  4. package/dist/js/modern/constants.js +35 -0
  5. package/dist/js/modern/index.js +18 -0
  6. package/dist/js/modern/libs/context/context.js +160 -0
  7. package/dist/js/modern/libs/context/index.js +6 -0
  8. package/dist/js/modern/libs/hook-api/index.js +134 -0
  9. package/dist/js/modern/libs/hook-api/route.js +20 -0
  10. package/dist/js/modern/libs/hook-api/template.js +73 -0
  11. package/dist/js/modern/libs/loadConfig.js +62 -0
  12. package/dist/js/modern/libs/logger.js +111 -0
  13. package/dist/js/modern/libs/metrics.js +11 -0
  14. package/dist/js/modern/libs/proxy.js +92 -0
  15. package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +114 -0
  16. package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +254 -0
  17. package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +47 -0
  18. package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +37 -0
  19. package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +91 -0
  20. package/dist/js/modern/libs/render/cache/index.js +115 -0
  21. package/dist/js/modern/libs/render/cache/page-caches/index.js +32 -0
  22. package/dist/js/modern/libs/render/cache/page-caches/lru.js +29 -0
  23. package/dist/js/modern/libs/render/cache/spr.js +248 -0
  24. package/dist/js/modern/libs/render/cache/type.js +0 -0
  25. package/dist/js/modern/libs/render/cache/util.js +102 -0
  26. package/dist/js/modern/libs/render/index.js +86 -0
  27. package/dist/js/modern/libs/render/measure.js +68 -0
  28. package/dist/js/modern/libs/render/reader.js +107 -0
  29. package/dist/js/modern/libs/render/ssr.js +100 -0
  30. package/dist/js/modern/libs/render/static.js +60 -0
  31. package/dist/js/modern/libs/render/type.js +9 -0
  32. package/dist/js/modern/libs/route/index.js +54 -0
  33. package/dist/js/modern/libs/route/matcher.js +87 -0
  34. package/dist/js/modern/libs/route/route.js +16 -0
  35. package/dist/js/modern/libs/serve-file.js +67 -0
  36. package/dist/js/modern/server/index.js +208 -0
  37. package/dist/js/modern/server/modern-server-split.js +74 -0
  38. package/dist/js/modern/server/modern-server.js +554 -0
  39. package/dist/js/modern/type.js +0 -0
  40. package/dist/js/modern/utils.js +136 -0
  41. package/dist/js/modern/worker-server.js +89 -0
  42. package/dist/js/node/constants.js +62 -0
  43. package/dist/js/node/index.js +44 -0
  44. package/dist/js/node/libs/context/context.js +189 -0
  45. package/dist/js/node/libs/context/index.js +30 -0
  46. package/dist/js/node/libs/hook-api/index.js +164 -0
  47. package/dist/js/node/libs/hook-api/route.js +43 -0
  48. package/dist/js/node/libs/hook-api/template.js +97 -0
  49. package/dist/js/node/libs/loadConfig.js +91 -0
  50. package/dist/js/node/libs/logger.js +133 -0
  51. package/dist/js/node/libs/metrics.js +34 -0
  52. package/dist/js/node/libs/proxy.js +114 -0
  53. package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +115 -0
  54. package/dist/js/node/libs/render/cache/__tests__/cache.test.js +245 -0
  55. package/dist/js/node/libs/render/cache/__tests__/cacheable.js +70 -0
  56. package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +60 -0
  57. package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +114 -0
  58. package/dist/js/node/libs/render/cache/index.js +134 -0
  59. package/dist/js/node/libs/render/cache/page-caches/index.js +55 -0
  60. package/dist/js/node/libs/render/cache/page-caches/lru.js +58 -0
  61. package/dist/js/node/libs/render/cache/spr.js +270 -0
  62. package/dist/js/node/libs/render/cache/type.js +15 -0
  63. package/dist/js/node/libs/render/cache/util.js +138 -0
  64. package/dist/js/node/libs/render/index.js +115 -0
  65. package/dist/js/node/libs/render/measure.js +90 -0
  66. package/dist/js/node/libs/render/reader.js +140 -0
  67. package/dist/js/node/libs/render/ssr.js +123 -0
  68. package/dist/js/node/libs/render/static.js +89 -0
  69. package/dist/js/node/libs/render/type.js +32 -0
  70. package/dist/js/node/libs/route/index.js +78 -0
  71. package/dist/js/node/libs/route/matcher.js +106 -0
  72. package/dist/js/node/libs/route/route.js +39 -0
  73. package/dist/js/node/libs/serve-file.js +97 -0
  74. package/dist/js/node/server/index.js +219 -0
  75. package/dist/js/node/server/modern-server-split.js +97 -0
  76. package/dist/js/node/server/modern-server.js +559 -0
  77. package/dist/js/node/type.js +15 -0
  78. package/dist/js/node/utils.js +166 -0
  79. package/dist/js/node/worker-server.js +113 -0
  80. package/dist/js/treeshaking/constants.js +29 -0
  81. package/dist/js/treeshaking/index.js +13 -0
  82. package/dist/js/treeshaking/libs/context/context.js +274 -0
  83. package/dist/js/treeshaking/libs/context/index.js +5 -0
  84. package/dist/js/treeshaking/libs/hook-api/index.js +281 -0
  85. package/dist/js/treeshaking/libs/hook-api/route.js +68 -0
  86. package/dist/js/treeshaking/libs/hook-api/template.js +127 -0
  87. package/dist/js/treeshaking/libs/loadConfig.js +82 -0
  88. package/dist/js/treeshaking/libs/logger.js +205 -0
  89. package/dist/js/treeshaking/libs/metrics.js +6 -0
  90. package/dist/js/treeshaking/libs/proxy.js +244 -0
  91. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +291 -0
  92. package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +781 -0
  93. package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +67 -0
  94. package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -0
  95. package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +147 -0
  96. package/dist/js/treeshaking/libs/render/cache/index.js +346 -0
  97. package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +154 -0
  98. package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +84 -0
  99. package/dist/js/treeshaking/libs/render/cache/spr.js +492 -0
  100. package/dist/js/treeshaking/libs/render/cache/type.js +1 -0
  101. package/dist/js/treeshaking/libs/render/cache/util.js +280 -0
  102. package/dist/js/treeshaking/libs/render/index.js +234 -0
  103. package/dist/js/treeshaking/libs/render/measure.js +146 -0
  104. package/dist/js/treeshaking/libs/render/reader.js +339 -0
  105. package/dist/js/treeshaking/libs/render/ssr.js +223 -0
  106. package/dist/js/treeshaking/libs/render/static.js +216 -0
  107. package/dist/js/treeshaking/libs/render/type.js +7 -0
  108. package/dist/js/treeshaking/libs/route/index.js +130 -0
  109. package/dist/js/treeshaking/libs/route/matcher.js +143 -0
  110. package/dist/js/treeshaking/libs/route/route.js +40 -0
  111. package/dist/js/treeshaking/libs/serve-file.js +184 -0
  112. package/dist/js/treeshaking/server/index.js +505 -0
  113. package/dist/js/treeshaking/server/modern-server-split.js +360 -0
  114. package/dist/js/treeshaking/server/modern-server.js +1089 -0
  115. package/dist/js/treeshaking/type.js +1 -0
  116. package/dist/js/treeshaking/utils.js +147 -0
  117. package/dist/js/treeshaking/worker-server.js +233 -0
  118. package/dist/types/libs/context/context.d.ts +1 -1
  119. package/dist/types/utils.d.ts +1 -1
  120. package/package.json +3 -3
@@ -0,0 +1,205 @@
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithHoles(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _arrayWithoutHoles(arr) {
10
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
11
+ }
12
+ function _classCallCheck(instance, Constructor) {
13
+ if (!(instance instanceof Constructor)) {
14
+ throw new TypeError("Cannot call a class as a function");
15
+ }
16
+ }
17
+ function _defineProperties(target, props) {
18
+ for(var i = 0; i < props.length; i++){
19
+ var descriptor = props[i];
20
+ descriptor.enumerable = descriptor.enumerable || false;
21
+ descriptor.configurable = true;
22
+ if ("value" in descriptor) descriptor.writable = true;
23
+ Object.defineProperty(target, descriptor.key, descriptor);
24
+ }
25
+ }
26
+ function _createClass(Constructor, protoProps, staticProps) {
27
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
28
+ if (staticProps) _defineProperties(Constructor, staticProps);
29
+ return Constructor;
30
+ }
31
+ function _defineProperty(obj, key, value) {
32
+ if (key in obj) {
33
+ Object.defineProperty(obj, key, {
34
+ value: value,
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true
38
+ });
39
+ } else {
40
+ obj[key] = value;
41
+ }
42
+ return obj;
43
+ }
44
+ function _instanceof(left, right) {
45
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
46
+ return !!right[Symbol.hasInstance](left);
47
+ } else {
48
+ return left instanceof right;
49
+ }
50
+ }
51
+ function _iterableToArray(iter) {
52
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
+ }
54
+ function _nonIterableRest() {
55
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
57
+ function _nonIterableSpread() {
58
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
59
+ }
60
+ function _objectSpread(target) {
61
+ for(var i = 1; i < arguments.length; i++){
62
+ var source = arguments[i] != null ? arguments[i] : {};
63
+ var ownKeys = Object.keys(source);
64
+ if (typeof Object.getOwnPropertySymbols === "function") {
65
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
66
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
67
+ }));
68
+ }
69
+ ownKeys.forEach(function(key) {
70
+ _defineProperty(target, key, source[key]);
71
+ });
72
+ }
73
+ return target;
74
+ }
75
+ function _toArray(arr) {
76
+ return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
77
+ }
78
+ function _toConsumableArray(arr) {
79
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
80
+ }
81
+ function _unsupportedIterableToArray(o, minLen) {
82
+ if (!o) return;
83
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
84
+ var n = Object.prototype.toString.call(o).slice(8, -1);
85
+ if (n === "Object" && o.constructor) n = o.constructor.name;
86
+ if (n === "Map" || n === "Set") return Array.from(n);
87
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
88
+ }
89
+ var LOG_LEVEL = {
90
+ error: 0,
91
+ warn: 1,
92
+ info: 2,
93
+ debug: 3,
94
+ log: 4
95
+ };
96
+ var LOG_TYPES = {
97
+ error: {
98
+ color: "red",
99
+ label: "error",
100
+ level: "error"
101
+ },
102
+ info: {
103
+ color: "cyan",
104
+ label: "info",
105
+ level: "info"
106
+ },
107
+ success: {
108
+ color: "green",
109
+ label: "Success",
110
+ level: "info"
111
+ },
112
+ warn: {
113
+ color: "yellow",
114
+ label: "warn",
115
+ level: "warn"
116
+ },
117
+ debug: {
118
+ color: "red",
119
+ label: "debug",
120
+ level: "debug"
121
+ },
122
+ log: {
123
+ level: "log"
124
+ }
125
+ };
126
+ var DEFAULT_CONFIG = {
127
+ displayLabel: true,
128
+ uppercaseLabel: false
129
+ };
130
+ var Logger = /*#__PURE__*/ function() {
131
+ "use strict";
132
+ function Logger() {
133
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
134
+ var _this = this;
135
+ _classCallCheck(this, Logger);
136
+ _defineProperty(this, "level", void 0);
137
+ _defineProperty(this, "config", void 0);
138
+ _defineProperty(this, "types", void 0);
139
+ _defineProperty(this, "longestLabel", void 0);
140
+ this.level = options.level || LOG_TYPES.log.level;
141
+ this.config = _objectSpread({}, DEFAULT_CONFIG, options.config || {});
142
+ this.types = _objectSpread({}, LOG_TYPES, options.types || {});
143
+ this.longestLabel = this.getLongestLabel();
144
+ Object.keys(this.types).forEach(function(type) {
145
+ _this[type] = _this._log.bind(_this, type);
146
+ });
147
+ }
148
+ _createClass(Logger, [
149
+ {
150
+ key: "_log",
151
+ value: function _log(type, message) {
152
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
153
+ args[_key - 2] = arguments[_key];
154
+ }
155
+ var _console;
156
+ if (message === void 0 || message === null) {
157
+ console.log();
158
+ return;
159
+ }
160
+ if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
161
+ return;
162
+ }
163
+ var label = "";
164
+ var text = "";
165
+ var logType = this.types[type];
166
+ if (this.config.displayLabel && logType.label) {
167
+ label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
168
+ label = label.padEnd(this.longestLabel.length);
169
+ }
170
+ if (_instanceof(message, Error)) {
171
+ if (message.stack) {
172
+ var _message_stack_split = _toArray(message.stack.split("\n")), name = _message_stack_split[0], rest = _message_stack_split.slice(1);
173
+ text = "".concat(name, "\n").concat(rest.join("\n"));
174
+ } else {
175
+ text = message.message;
176
+ }
177
+ } else {
178
+ text = "".concat(message);
179
+ }
180
+ var log = label.length > 0 ? "".concat(label, " ").concat(text) : text;
181
+ (_console = console).log.apply(_console, [
182
+ log
183
+ ].concat(_toConsumableArray(args)));
184
+ }
185
+ },
186
+ {
187
+ key: "getLongestLabel",
188
+ value: function getLongestLabel() {
189
+ var _this = this;
190
+ var longestLabel = "";
191
+ Object.keys(this.types).forEach(function(type) {
192
+ var _this_types_type = _this.types[type], _this_types_type_label = _this_types_type.label, label = _this_types_type_label === void 0 ? "" : _this_types_type_label;
193
+ if (label.length > longestLabel.length) {
194
+ longestLabel = label;
195
+ }
196
+ });
197
+ return longestLabel;
198
+ }
199
+ }
200
+ ]);
201
+ return Logger;
202
+ }();
203
+ var logger = new Logger();
204
+ logger.Logger = Logger;
205
+ export { Logger, logger };
@@ -0,0 +1,6 @@
1
+ var metrics = {
2
+ gauges: function gauges() {},
3
+ emitCounter: function emitCounter() {},
4
+ emitTimer: function emitTimer() {}
5
+ };
6
+ export { metrics };
@@ -0,0 +1,244 @@
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithoutHoles(arr) {
7
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _asyncToGenerator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _defineProperty(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
51
+ function _iterableToArray(iter) {
52
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
+ }
54
+ function _nonIterableSpread() {
55
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
57
+ function _objectSpread(target) {
58
+ for(var i = 1; i < arguments.length; i++){
59
+ var source = arguments[i] != null ? arguments[i] : {};
60
+ var ownKeys = Object.keys(source);
61
+ if (typeof Object.getOwnPropertySymbols === "function") {
62
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
63
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
64
+ }));
65
+ }
66
+ ownKeys.forEach(function(key) {
67
+ _defineProperty(target, key, source[key]);
68
+ });
69
+ }
70
+ return target;
71
+ }
72
+ function _toConsumableArray(arr) {
73
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
74
+ }
75
+ function _unsupportedIterableToArray(o, minLen) {
76
+ if (!o) return;
77
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
78
+ var n = Object.prototype.toString.call(o).slice(8, -1);
79
+ if (n === "Object" && o.constructor) n = o.constructor.name;
80
+ if (n === "Map" || n === "Set") return Array.from(n);
81
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
82
+ }
83
+ var __generator = this && this.__generator || function(thisArg, body) {
84
+ var f, y, t, g, _ = {
85
+ label: 0,
86
+ sent: function() {
87
+ if (t[0] & 1) throw t[1];
88
+ return t[1];
89
+ },
90
+ trys: [],
91
+ ops: []
92
+ };
93
+ return(g = {
94
+ next: verb(0),
95
+ "throw": verb(1),
96
+ "return": verb(2)
97
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
98
+ return this;
99
+ }), g);
100
+ function verb(n) {
101
+ return function(v) {
102
+ return step([
103
+ n,
104
+ v
105
+ ]);
106
+ };
107
+ }
108
+ function step(op) {
109
+ if (f) throw new TypeError("Generator is already executing.");
110
+ while(_)try {
111
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
112
+ if (y = 0, t) op = [
113
+ op[0] & 2,
114
+ t.value
115
+ ];
116
+ switch(op[0]){
117
+ case 0:
118
+ case 1:
119
+ t = op;
120
+ break;
121
+ case 4:
122
+ _.label++;
123
+ return {
124
+ value: op[1],
125
+ done: false
126
+ };
127
+ case 5:
128
+ _.label++;
129
+ y = op[1];
130
+ op = [
131
+ 0
132
+ ];
133
+ continue;
134
+ case 7:
135
+ op = _.ops.pop();
136
+ _.trys.pop();
137
+ continue;
138
+ default:
139
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
140
+ _ = 0;
141
+ continue;
142
+ }
143
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
144
+ _.label = op[1];
145
+ break;
146
+ }
147
+ if (op[0] === 6 && _.label < t[1]) {
148
+ _.label = t[1];
149
+ t = op;
150
+ break;
151
+ }
152
+ if (t && _.label < t[2]) {
153
+ _.label = t[2];
154
+ _.ops.push(op);
155
+ break;
156
+ }
157
+ if (t[2]) _.ops.pop();
158
+ _.trys.pop();
159
+ continue;
160
+ }
161
+ op = body.call(thisArg, _);
162
+ } catch (e) {
163
+ op = [
164
+ 6,
165
+ e
166
+ ];
167
+ y = 0;
168
+ } finally{
169
+ f = t = 0;
170
+ }
171
+ if (op[0] & 5) throw op[1];
172
+ return {
173
+ value: op[0] ? op[1] : void 0,
174
+ done: true
175
+ };
176
+ }
177
+ };
178
+ import { createProxyMiddleware } from "http-proxy-middleware";
179
+ import { debug } from "../utils";
180
+ function formatProxyOptions(proxyOptions) {
181
+ var formattedProxy = [];
182
+ if (!Array.isArray(proxyOptions)) {
183
+ if ("target" in proxyOptions) {
184
+ formattedProxy.push(proxyOptions);
185
+ } else {
186
+ Array.prototype.push.apply(formattedProxy, Object.keys(proxyOptions).reduce(function(total, source) {
187
+ var option = proxyOptions[source];
188
+ total.push(_objectSpread({
189
+ context: source,
190
+ changeOrigin: true,
191
+ logLevel: "warn"
192
+ }, typeof option === "string" ? {
193
+ target: option
194
+ } : option));
195
+ return total;
196
+ }, []));
197
+ }
198
+ } else {
199
+ var _formattedProxy;
200
+ (_formattedProxy = formattedProxy).push.apply(_formattedProxy, _toConsumableArray(proxyOptions));
201
+ }
202
+ return formattedProxy;
203
+ }
204
+ var createProxyHandler = function(proxyOptions) {
205
+ debug("createProxyHandler", proxyOptions);
206
+ if (!proxyOptions) {
207
+ return null;
208
+ }
209
+ var formattedProxy = formatProxyOptions(proxyOptions);
210
+ var middlewares = formattedProxy.map(function(option) {
211
+ var middleware = createProxyMiddleware(option.context, option);
212
+ return function() {
213
+ var _ref = _asyncToGenerator(function(ctx, next) {
214
+ var req, res, bypassUrl;
215
+ return __generator(this, function(_state) {
216
+ req = ctx.req, res = ctx.res;
217
+ bypassUrl = typeof option.bypass === "function" ? option.bypass(req, res, option) : null;
218
+ if (typeof bypassUrl === "boolean") {
219
+ ctx.status = 404;
220
+ return [
221
+ 2,
222
+ next()
223
+ ];
224
+ } else if (typeof bypassUrl === "string") {
225
+ ctx.url = bypassUrl;
226
+ return [
227
+ 2,
228
+ next()
229
+ ];
230
+ }
231
+ middleware(req, res, next);
232
+ return [
233
+ 2
234
+ ];
235
+ });
236
+ });
237
+ return function(ctx, next) {
238
+ return _ref.apply(this, arguments);
239
+ };
240
+ }();
241
+ });
242
+ return middlewares;
243
+ };
244
+ export { createProxyHandler, formatProxyOptions };