@rspack/dev-server 2.0.0-rc.3 → 2.0.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.
@@ -1,7 +1,16 @@
1
1
  /*! LICENSE: 0~http-proxy-middleware.js.LICENSE.txt */
2
- import { __webpack_require__ } from "./937.js";
3
- import "./937.js";
2
+ import node_http from "node:http";
3
+ import node_https from "node:https";
4
+ import node_http2 from "node:http2";
5
+ import { EventEmitter } from "node:events";
6
+ import "node:net";
7
+ import "node:stream";
8
+ import { URL as external_node_url_URL } from "node:url";
9
+ import "node:zlib";
10
+ import "node:querystring";
11
+ import { __webpack_require__ } from "./198.js";
4
12
  import "./0~debug.js";
13
+ import "./198.js";
5
14
  __webpack_require__.add({
6
15
  "./node_modules/.pnpm/braces@3.0.3/node_modules/braces/index.js" (module, __unused_rspack_exports, __webpack_require__) {
7
16
  const stringify = __webpack_require__("./node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/stringify.js");
@@ -543,146 +552,6 @@ __webpack_require__.add({
543
552
  return result;
544
553
  };
545
554
  },
546
- "./node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.js" (module) {
547
- var has = Object.prototype.hasOwnProperty, prefix = '~';
548
- function Events() {}
549
- if (Object.create) {
550
- Events.prototype = Object.create(null);
551
- if (!new Events().__proto__) prefix = false;
552
- }
553
- function EE(fn, context, once) {
554
- this.fn = fn;
555
- this.context = context;
556
- this.once = once || false;
557
- }
558
- function addListener(emitter, event, fn, context, once) {
559
- if ('function' != typeof fn) throw new TypeError('The listener must be a function');
560
- var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
561
- if (emitter._events[evt]) if (emitter._events[evt].fn) emitter._events[evt] = [
562
- emitter._events[evt],
563
- listener
564
- ];
565
- else emitter._events[evt].push(listener);
566
- else emitter._events[evt] = listener, emitter._eventsCount++;
567
- return emitter;
568
- }
569
- function clearEvent(emitter, evt) {
570
- if (0 === --emitter._eventsCount) emitter._events = new Events();
571
- else delete emitter._events[evt];
572
- }
573
- function EventEmitter() {
574
- this._events = new Events();
575
- this._eventsCount = 0;
576
- }
577
- EventEmitter.prototype.eventNames = function() {
578
- var names = [], events, name;
579
- if (0 === this._eventsCount) return names;
580
- for(name in events = this._events)if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
581
- if (Object.getOwnPropertySymbols) return names.concat(Object.getOwnPropertySymbols(events));
582
- return names;
583
- };
584
- EventEmitter.prototype.listeners = function(event) {
585
- var evt = prefix ? prefix + event : event, handlers = this._events[evt];
586
- if (!handlers) return [];
587
- if (handlers.fn) return [
588
- handlers.fn
589
- ];
590
- for(var i = 0, l = handlers.length, ee = new Array(l); i < l; i++)ee[i] = handlers[i].fn;
591
- return ee;
592
- };
593
- EventEmitter.prototype.listenerCount = function(event) {
594
- var evt = prefix ? prefix + event : event, listeners = this._events[evt];
595
- if (!listeners) return 0;
596
- if (listeners.fn) return 1;
597
- return listeners.length;
598
- };
599
- EventEmitter.prototype.emit = function(event, a1, a2, a3, a4, a5) {
600
- var evt = prefix ? prefix + event : event;
601
- if (!this._events[evt]) return false;
602
- var listeners = this._events[evt], len = arguments.length, args, i;
603
- if (listeners.fn) {
604
- if (listeners.once) this.removeListener(event, listeners.fn, void 0, true);
605
- switch(len){
606
- case 1:
607
- return listeners.fn.call(listeners.context), true;
608
- case 2:
609
- return listeners.fn.call(listeners.context, a1), true;
610
- case 3:
611
- return listeners.fn.call(listeners.context, a1, a2), true;
612
- case 4:
613
- return listeners.fn.call(listeners.context, a1, a2, a3), true;
614
- case 5:
615
- return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
616
- case 6:
617
- return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
618
- }
619
- for(i = 1, args = new Array(len - 1); i < len; i++)args[i - 1] = arguments[i];
620
- listeners.fn.apply(listeners.context, args);
621
- } else {
622
- var length = listeners.length, j;
623
- for(i = 0; i < length; i++){
624
- if (listeners[i].once) this.removeListener(event, listeners[i].fn, void 0, true);
625
- switch(len){
626
- case 1:
627
- listeners[i].fn.call(listeners[i].context);
628
- break;
629
- case 2:
630
- listeners[i].fn.call(listeners[i].context, a1);
631
- break;
632
- case 3:
633
- listeners[i].fn.call(listeners[i].context, a1, a2);
634
- break;
635
- case 4:
636
- listeners[i].fn.call(listeners[i].context, a1, a2, a3);
637
- break;
638
- default:
639
- if (!args) for(j = 1, args = new Array(len - 1); j < len; j++)args[j - 1] = arguments[j];
640
- listeners[i].fn.apply(listeners[i].context, args);
641
- }
642
- }
643
- }
644
- return true;
645
- };
646
- EventEmitter.prototype.on = function(event, fn, context) {
647
- return addListener(this, event, fn, context, false);
648
- };
649
- EventEmitter.prototype.once = function(event, fn, context) {
650
- return addListener(this, event, fn, context, true);
651
- };
652
- EventEmitter.prototype.removeListener = function(event, fn, context, once) {
653
- var evt = prefix ? prefix + event : event;
654
- if (!this._events[evt]) return this;
655
- if (!fn) {
656
- clearEvent(this, evt);
657
- return this;
658
- }
659
- var listeners = this._events[evt];
660
- if (listeners.fn) {
661
- if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) clearEvent(this, evt);
662
- } else {
663
- for(var i = 0, events = [], length = listeners.length; i < length; i++)if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) events.push(listeners[i]);
664
- if (events.length) this._events[evt] = 1 === events.length ? events[0] : events;
665
- else clearEvent(this, evt);
666
- }
667
- return this;
668
- };
669
- EventEmitter.prototype.removeAllListeners = function(event) {
670
- var evt;
671
- if (event) {
672
- evt = prefix ? prefix + event : event;
673
- if (this._events[evt]) clearEvent(this, evt);
674
- } else {
675
- this._events = new Events();
676
- this._eventsCount = 0;
677
- }
678
- return this;
679
- };
680
- EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
681
- EventEmitter.prototype.addListener = EventEmitter.prototype.on;
682
- EventEmitter.prefixed = prefix;
683
- EventEmitter.EventEmitter = EventEmitter;
684
- module.exports = EventEmitter;
685
- },
686
555
  "./node_modules/.pnpm/fill-range@7.1.1/node_modules/fill-range/index.js" (module, __unused_rspack_exports, __webpack_require__) {
687
556
  /*!
688
557
  * fill-range <https://github.com/jonschlinkert/fill-range>
@@ -854,886 +723,6 @@ __webpack_require__.add({
854
723
  };
855
724
  module.exports = fill;
856
725
  },
857
- "./node_modules/.pnpm/follow-redirects@1.15.11_debug@4.4.3/node_modules/follow-redirects/debug.js" (module, __unused_rspack_exports, __webpack_require__) {
858
- var debug;
859
- module.exports = function() {
860
- if (!debug) {
861
- try {
862
- debug = __webpack_require__("./node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/index.js")("follow-redirects");
863
- } catch (error) {}
864
- if ("function" != typeof debug) debug = function() {};
865
- }
866
- debug.apply(null, arguments);
867
- };
868
- },
869
- "./node_modules/.pnpm/follow-redirects@1.15.11_debug@4.4.3/node_modules/follow-redirects/index.js" (module, __unused_rspack_exports, __webpack_require__) {
870
- var url = __webpack_require__("url");
871
- var URL = url.URL;
872
- var http = __webpack_require__("http");
873
- var https = __webpack_require__("https");
874
- var Writable = __webpack_require__("stream").Writable;
875
- var assert = __webpack_require__("assert");
876
- var debug = __webpack_require__("./node_modules/.pnpm/follow-redirects@1.15.11_debug@4.4.3/node_modules/follow-redirects/debug.js");
877
- (function() {
878
- var looksLikeNode = "u" > typeof process;
879
- var looksLikeBrowser = "u" > typeof window && "u" > typeof document;
880
- var looksLikeV8 = isFunction(Error.captureStackTrace);
881
- if (!looksLikeNode && (looksLikeBrowser || !looksLikeV8)) console.warn("The follow-redirects package should be excluded from browser builds.");
882
- })();
883
- var useNativeURL = false;
884
- try {
885
- assert(new URL(""));
886
- } catch (error) {
887
- useNativeURL = "ERR_INVALID_URL" === error.code;
888
- }
889
- var preservedUrlFields = [
890
- "auth",
891
- "host",
892
- "hostname",
893
- "href",
894
- "path",
895
- "pathname",
896
- "port",
897
- "protocol",
898
- "query",
899
- "search",
900
- "hash"
901
- ];
902
- var events = [
903
- "abort",
904
- "aborted",
905
- "connect",
906
- "error",
907
- "socket",
908
- "timeout"
909
- ];
910
- var eventHandlers = Object.create(null);
911
- events.forEach(function(event) {
912
- eventHandlers[event] = function(arg1, arg2, arg3) {
913
- this._redirectable.emit(event, arg1, arg2, arg3);
914
- };
915
- });
916
- var InvalidUrlError = createErrorType("ERR_INVALID_URL", "Invalid URL", TypeError);
917
- var RedirectionError = createErrorType("ERR_FR_REDIRECTION_FAILURE", "Redirected request failed");
918
- var TooManyRedirectsError = createErrorType("ERR_FR_TOO_MANY_REDIRECTS", "Maximum number of redirects exceeded", RedirectionError);
919
- var MaxBodyLengthExceededError = createErrorType("ERR_FR_MAX_BODY_LENGTH_EXCEEDED", "Request body larger than maxBodyLength limit");
920
- var WriteAfterEndError = createErrorType("ERR_STREAM_WRITE_AFTER_END", "write after end");
921
- var destroy = Writable.prototype.destroy || noop;
922
- function RedirectableRequest(options, responseCallback) {
923
- Writable.call(this);
924
- this._sanitizeOptions(options);
925
- this._options = options;
926
- this._ended = false;
927
- this._ending = false;
928
- this._redirectCount = 0;
929
- this._redirects = [];
930
- this._requestBodyLength = 0;
931
- this._requestBodyBuffers = [];
932
- if (responseCallback) this.on("response", responseCallback);
933
- var self = this;
934
- this._onNativeResponse = function(response) {
935
- try {
936
- self._processResponse(response);
937
- } catch (cause) {
938
- self.emit("error", cause instanceof RedirectionError ? cause : new RedirectionError({
939
- cause: cause
940
- }));
941
- }
942
- };
943
- this._performRequest();
944
- }
945
- RedirectableRequest.prototype = Object.create(Writable.prototype);
946
- RedirectableRequest.prototype.abort = function() {
947
- destroyRequest(this._currentRequest);
948
- this._currentRequest.abort();
949
- this.emit("abort");
950
- };
951
- RedirectableRequest.prototype.destroy = function(error) {
952
- destroyRequest(this._currentRequest, error);
953
- destroy.call(this, error);
954
- return this;
955
- };
956
- RedirectableRequest.prototype.write = function(data, encoding, callback) {
957
- if (this._ending) throw new WriteAfterEndError();
958
- if (!isString(data) && !isBuffer(data)) throw new TypeError("data should be a string, Buffer or Uint8Array");
959
- if (isFunction(encoding)) {
960
- callback = encoding;
961
- encoding = null;
962
- }
963
- if (0 === data.length) {
964
- if (callback) callback();
965
- return;
966
- }
967
- if (this._requestBodyLength + data.length <= this._options.maxBodyLength) {
968
- this._requestBodyLength += data.length;
969
- this._requestBodyBuffers.push({
970
- data: data,
971
- encoding: encoding
972
- });
973
- this._currentRequest.write(data, encoding, callback);
974
- } else {
975
- this.emit("error", new MaxBodyLengthExceededError());
976
- this.abort();
977
- }
978
- };
979
- RedirectableRequest.prototype.end = function(data, encoding, callback) {
980
- if (isFunction(data)) {
981
- callback = data;
982
- data = encoding = null;
983
- } else if (isFunction(encoding)) {
984
- callback = encoding;
985
- encoding = null;
986
- }
987
- if (data) {
988
- var self = this;
989
- var currentRequest = this._currentRequest;
990
- this.write(data, encoding, function() {
991
- self._ended = true;
992
- currentRequest.end(null, null, callback);
993
- });
994
- this._ending = true;
995
- } else {
996
- this._ended = this._ending = true;
997
- this._currentRequest.end(null, null, callback);
998
- }
999
- };
1000
- RedirectableRequest.prototype.setHeader = function(name, value) {
1001
- this._options.headers[name] = value;
1002
- this._currentRequest.setHeader(name, value);
1003
- };
1004
- RedirectableRequest.prototype.removeHeader = function(name) {
1005
- delete this._options.headers[name];
1006
- this._currentRequest.removeHeader(name);
1007
- };
1008
- RedirectableRequest.prototype.setTimeout = function(msecs, callback) {
1009
- var self = this;
1010
- function destroyOnTimeout(socket) {
1011
- socket.setTimeout(msecs);
1012
- socket.removeListener("timeout", socket.destroy);
1013
- socket.addListener("timeout", socket.destroy);
1014
- }
1015
- function startTimer(socket) {
1016
- if (self._timeout) clearTimeout(self._timeout);
1017
- self._timeout = setTimeout(function() {
1018
- self.emit("timeout");
1019
- clearTimer();
1020
- }, msecs);
1021
- destroyOnTimeout(socket);
1022
- }
1023
- function clearTimer() {
1024
- if (self._timeout) {
1025
- clearTimeout(self._timeout);
1026
- self._timeout = null;
1027
- }
1028
- self.removeListener("abort", clearTimer);
1029
- self.removeListener("error", clearTimer);
1030
- self.removeListener("response", clearTimer);
1031
- self.removeListener("close", clearTimer);
1032
- if (callback) self.removeListener("timeout", callback);
1033
- if (!self.socket) self._currentRequest.removeListener("socket", startTimer);
1034
- }
1035
- if (callback) this.on("timeout", callback);
1036
- if (this.socket) startTimer(this.socket);
1037
- else this._currentRequest.once("socket", startTimer);
1038
- this.on("socket", destroyOnTimeout);
1039
- this.on("abort", clearTimer);
1040
- this.on("error", clearTimer);
1041
- this.on("response", clearTimer);
1042
- this.on("close", clearTimer);
1043
- return this;
1044
- };
1045
- [
1046
- "flushHeaders",
1047
- "getHeader",
1048
- "setNoDelay",
1049
- "setSocketKeepAlive"
1050
- ].forEach(function(method) {
1051
- RedirectableRequest.prototype[method] = function(a, b) {
1052
- return this._currentRequest[method](a, b);
1053
- };
1054
- });
1055
- [
1056
- "aborted",
1057
- "connection",
1058
- "socket"
1059
- ].forEach(function(property) {
1060
- Object.defineProperty(RedirectableRequest.prototype, property, {
1061
- get: function() {
1062
- return this._currentRequest[property];
1063
- }
1064
- });
1065
- });
1066
- RedirectableRequest.prototype._sanitizeOptions = function(options) {
1067
- if (!options.headers) options.headers = {};
1068
- if (options.host) {
1069
- if (!options.hostname) options.hostname = options.host;
1070
- delete options.host;
1071
- }
1072
- if (!options.pathname && options.path) {
1073
- var searchPos = options.path.indexOf("?");
1074
- if (searchPos < 0) options.pathname = options.path;
1075
- else {
1076
- options.pathname = options.path.substring(0, searchPos);
1077
- options.search = options.path.substring(searchPos);
1078
- }
1079
- }
1080
- };
1081
- RedirectableRequest.prototype._performRequest = function() {
1082
- var protocol = this._options.protocol;
1083
- var nativeProtocol = this._options.nativeProtocols[protocol];
1084
- if (!nativeProtocol) throw new TypeError("Unsupported protocol " + protocol);
1085
- if (this._options.agents) {
1086
- var scheme = protocol.slice(0, -1);
1087
- this._options.agent = this._options.agents[scheme];
1088
- }
1089
- var request = this._currentRequest = nativeProtocol.request(this._options, this._onNativeResponse);
1090
- request._redirectable = this;
1091
- for (var event of events)request.on(event, eventHandlers[event]);
1092
- this._currentUrl = /^\//.test(this._options.path) ? url.format(this._options) : this._options.path;
1093
- if (this._isRedirect) {
1094
- var i = 0;
1095
- var self = this;
1096
- var buffers = this._requestBodyBuffers;
1097
- (function writeNext(error) {
1098
- if (request === self._currentRequest) {
1099
- if (error) self.emit("error", error);
1100
- else if (i < buffers.length) {
1101
- var buffer = buffers[i++];
1102
- if (!request.finished) request.write(buffer.data, buffer.encoding, writeNext);
1103
- } else if (self._ended) request.end();
1104
- }
1105
- })();
1106
- }
1107
- };
1108
- RedirectableRequest.prototype._processResponse = function(response) {
1109
- var statusCode = response.statusCode;
1110
- if (this._options.trackRedirects) this._redirects.push({
1111
- url: this._currentUrl,
1112
- headers: response.headers,
1113
- statusCode: statusCode
1114
- });
1115
- var location = response.headers.location;
1116
- if (!location || false === this._options.followRedirects || statusCode < 300 || statusCode >= 400) {
1117
- response.responseUrl = this._currentUrl;
1118
- response.redirects = this._redirects;
1119
- this.emit("response", response);
1120
- this._requestBodyBuffers = [];
1121
- return;
1122
- }
1123
- destroyRequest(this._currentRequest);
1124
- response.destroy();
1125
- if (++this._redirectCount > this._options.maxRedirects) throw new TooManyRedirectsError();
1126
- var requestHeaders;
1127
- var beforeRedirect = this._options.beforeRedirect;
1128
- if (beforeRedirect) requestHeaders = Object.assign({
1129
- Host: response.req.getHeader("host")
1130
- }, this._options.headers);
1131
- var method = this._options.method;
1132
- if ((301 === statusCode || 302 === statusCode) && "POST" === this._options.method || 303 === statusCode && !/^(?:GET|HEAD)$/.test(this._options.method)) {
1133
- this._options.method = "GET";
1134
- this._requestBodyBuffers = [];
1135
- removeMatchingHeaders(/^content-/i, this._options.headers);
1136
- }
1137
- var currentHostHeader = removeMatchingHeaders(/^host$/i, this._options.headers);
1138
- var currentUrlParts = parseUrl(this._currentUrl);
1139
- var currentHost = currentHostHeader || currentUrlParts.host;
1140
- var currentUrl = /^\w+:/.test(location) ? this._currentUrl : url.format(Object.assign(currentUrlParts, {
1141
- host: currentHost
1142
- }));
1143
- var redirectUrl = resolveUrl(location, currentUrl);
1144
- debug("redirecting to", redirectUrl.href);
1145
- this._isRedirect = true;
1146
- spreadUrlObject(redirectUrl, this._options);
1147
- if (redirectUrl.protocol !== currentUrlParts.protocol && "https:" !== redirectUrl.protocol || redirectUrl.host !== currentHost && !isSubdomain(redirectUrl.host, currentHost)) removeMatchingHeaders(/^(?:(?:proxy-)?authorization|cookie)$/i, this._options.headers);
1148
- if (isFunction(beforeRedirect)) {
1149
- var responseDetails = {
1150
- headers: response.headers,
1151
- statusCode: statusCode
1152
- };
1153
- var requestDetails = {
1154
- url: currentUrl,
1155
- method: method,
1156
- headers: requestHeaders
1157
- };
1158
- beforeRedirect(this._options, responseDetails, requestDetails);
1159
- this._sanitizeOptions(this._options);
1160
- }
1161
- this._performRequest();
1162
- };
1163
- function wrap(protocols) {
1164
- var exports = {
1165
- maxRedirects: 21,
1166
- maxBodyLength: 10485760
1167
- };
1168
- var nativeProtocols = {};
1169
- Object.keys(protocols).forEach(function(scheme) {
1170
- var protocol = scheme + ":";
1171
- var nativeProtocol = nativeProtocols[protocol] = protocols[scheme];
1172
- var wrappedProtocol = exports[scheme] = Object.create(nativeProtocol);
1173
- function request(input, options, callback) {
1174
- if (isURL(input)) input = spreadUrlObject(input);
1175
- else if (isString(input)) input = spreadUrlObject(parseUrl(input));
1176
- else {
1177
- callback = options;
1178
- options = validateUrl(input);
1179
- input = {
1180
- protocol: protocol
1181
- };
1182
- }
1183
- if (isFunction(options)) {
1184
- callback = options;
1185
- options = null;
1186
- }
1187
- options = Object.assign({
1188
- maxRedirects: exports.maxRedirects,
1189
- maxBodyLength: exports.maxBodyLength
1190
- }, input, options);
1191
- options.nativeProtocols = nativeProtocols;
1192
- if (!isString(options.host) && !isString(options.hostname)) options.hostname = "::1";
1193
- assert.equal(options.protocol, protocol, "protocol mismatch");
1194
- debug("options", options);
1195
- return new RedirectableRequest(options, callback);
1196
- }
1197
- function get(input, options, callback) {
1198
- var wrappedRequest = wrappedProtocol.request(input, options, callback);
1199
- wrappedRequest.end();
1200
- return wrappedRequest;
1201
- }
1202
- Object.defineProperties(wrappedProtocol, {
1203
- request: {
1204
- value: request,
1205
- configurable: true,
1206
- enumerable: true,
1207
- writable: true
1208
- },
1209
- get: {
1210
- value: get,
1211
- configurable: true,
1212
- enumerable: true,
1213
- writable: true
1214
- }
1215
- });
1216
- });
1217
- return exports;
1218
- }
1219
- function noop() {}
1220
- function parseUrl(input) {
1221
- var parsed;
1222
- if (useNativeURL) parsed = new URL(input);
1223
- else {
1224
- parsed = validateUrl(url.parse(input));
1225
- if (!isString(parsed.protocol)) throw new InvalidUrlError({
1226
- input
1227
- });
1228
- }
1229
- return parsed;
1230
- }
1231
- function resolveUrl(relative, base) {
1232
- return useNativeURL ? new URL(relative, base) : parseUrl(url.resolve(base, relative));
1233
- }
1234
- function validateUrl(input) {
1235
- if (/^\[/.test(input.hostname) && !/^\[[:0-9a-f]+\]$/i.test(input.hostname)) throw new InvalidUrlError({
1236
- input: input.href || input
1237
- });
1238
- if (/^\[/.test(input.host) && !/^\[[:0-9a-f]+\](:\d+)?$/i.test(input.host)) throw new InvalidUrlError({
1239
- input: input.href || input
1240
- });
1241
- return input;
1242
- }
1243
- function spreadUrlObject(urlObject, target) {
1244
- var spread = target || {};
1245
- for (var key of preservedUrlFields)spread[key] = urlObject[key];
1246
- if (spread.hostname.startsWith("[")) spread.hostname = spread.hostname.slice(1, -1);
1247
- if ("" !== spread.port) spread.port = Number(spread.port);
1248
- spread.path = spread.search ? spread.pathname + spread.search : spread.pathname;
1249
- return spread;
1250
- }
1251
- function removeMatchingHeaders(regex, headers) {
1252
- var lastValue;
1253
- for(var header in headers)if (regex.test(header)) {
1254
- lastValue = headers[header];
1255
- delete headers[header];
1256
- }
1257
- return null == lastValue ? void 0 : String(lastValue).trim();
1258
- }
1259
- function createErrorType(code, message, baseClass) {
1260
- function CustomError(properties) {
1261
- if (isFunction(Error.captureStackTrace)) Error.captureStackTrace(this, this.constructor);
1262
- Object.assign(this, properties || {});
1263
- this.code = code;
1264
- this.message = this.cause ? message + ": " + this.cause.message : message;
1265
- }
1266
- CustomError.prototype = new (baseClass || Error)();
1267
- Object.defineProperties(CustomError.prototype, {
1268
- constructor: {
1269
- value: CustomError,
1270
- enumerable: false
1271
- },
1272
- name: {
1273
- value: "Error [" + code + "]",
1274
- enumerable: false
1275
- }
1276
- });
1277
- return CustomError;
1278
- }
1279
- function destroyRequest(request, error) {
1280
- for (var event of events)request.removeListener(event, eventHandlers[event]);
1281
- request.on("error", noop);
1282
- request.destroy(error);
1283
- }
1284
- function isSubdomain(subdomain, domain) {
1285
- assert(isString(subdomain) && isString(domain));
1286
- var dot = subdomain.length - domain.length - 1;
1287
- return dot > 0 && "." === subdomain[dot] && subdomain.endsWith(domain);
1288
- }
1289
- function isString(value) {
1290
- return "string" == typeof value || value instanceof String;
1291
- }
1292
- function isFunction(value) {
1293
- return "function" == typeof value;
1294
- }
1295
- function isBuffer(value) {
1296
- return "object" == typeof value && "length" in value;
1297
- }
1298
- function isURL(value) {
1299
- return URL && value instanceof URL;
1300
- }
1301
- module.exports = wrap({
1302
- http: http,
1303
- https: https
1304
- });
1305
- module.exports.wrap = wrap;
1306
- },
1307
- "./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/index.js" (module, __unused_rspack_exports, __webpack_require__) {
1308
- /*!
1309
- * Caron dimonio, con occhi di bragia
1310
- * loro accennando, tutte le raccoglie;
1311
- * batte col remo qualunque s’adagia
1312
- *
1313
- * Charon the demon, with the eyes of glede,
1314
- * Beckoning to them, collects them all together,
1315
- * Beats with his oar whoever lags behind
1316
- *
1317
- * Dante - The Divine Comedy (Canto III)
1318
- */ module.exports = __webpack_require__("./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy.js");
1319
- },
1320
- "./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy.js" (module, __unused_rspack_exports, __webpack_require__) {
1321
- var ProxyServer = __webpack_require__("./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/index.js").Server;
1322
- function createProxyServer(options) {
1323
- return new ProxyServer(options);
1324
- }
1325
- ProxyServer.createProxyServer = createProxyServer;
1326
- ProxyServer.createServer = createProxyServer;
1327
- ProxyServer.createProxy = createProxyServer;
1328
- module.exports = ProxyServer;
1329
- },
1330
- "./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/common.js" (__unused_rspack_module, exports, __webpack_require__) {
1331
- var common = exports, url = __webpack_require__("url"), extend = __webpack_require__("util")._extend, required = __webpack_require__("./node_modules/.pnpm/requires-port@1.0.0/node_modules/requires-port/index.js");
1332
- var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i, isSSL = /^https|wss/;
1333
- common.isSSL = isSSL;
1334
- common.setupOutgoing = function(outgoing, options, req, forward) {
1335
- outgoing.port = options[forward || 'target'].port || (isSSL.test(options[forward || 'target'].protocol) ? 443 : 80);
1336
- [
1337
- 'host',
1338
- 'hostname',
1339
- 'socketPath',
1340
- 'pfx',
1341
- 'key',
1342
- 'passphrase',
1343
- 'cert',
1344
- 'ca',
1345
- 'ciphers',
1346
- 'secureProtocol'
1347
- ].forEach(function(e) {
1348
- outgoing[e] = options[forward || 'target'][e];
1349
- });
1350
- outgoing.method = options.method || req.method;
1351
- outgoing.headers = extend({}, req.headers);
1352
- if (options.headers) extend(outgoing.headers, options.headers);
1353
- if (options.auth) outgoing.auth = options.auth;
1354
- if (options.ca) outgoing.ca = options.ca;
1355
- if (isSSL.test(options[forward || 'target'].protocol)) outgoing.rejectUnauthorized = void 0 === options.secure ? true : options.secure;
1356
- outgoing.agent = options.agent || false;
1357
- outgoing.localAddress = options.localAddress;
1358
- if (!outgoing.agent) {
1359
- outgoing.headers = outgoing.headers || {};
1360
- if ('string' != typeof outgoing.headers.connection || !upgradeHeader.test(outgoing.headers.connection)) outgoing.headers.connection = 'close';
1361
- }
1362
- var target = options[forward || 'target'];
1363
- var targetPath = target && false !== options.prependPath ? target.path || '' : '';
1364
- var outgoingPath = options.toProxy ? req.url : url.parse(req.url).path || '';
1365
- outgoingPath = options.ignorePath ? '' : outgoingPath;
1366
- outgoing.path = common.urlJoin(targetPath, outgoingPath);
1367
- if (options.changeOrigin) outgoing.headers.host = required(outgoing.port, options[forward || 'target'].protocol) && !hasPort(outgoing.host) ? outgoing.host + ':' + outgoing.port : outgoing.host;
1368
- return outgoing;
1369
- };
1370
- common.setupSocket = function(socket) {
1371
- socket.setTimeout(0);
1372
- socket.setNoDelay(true);
1373
- socket.setKeepAlive(true, 0);
1374
- return socket;
1375
- };
1376
- common.getPort = function(req) {
1377
- var res = req.headers.host ? req.headers.host.match(/:(\d+)/) : '';
1378
- return res ? res[1] : common.hasEncryptedConnection(req) ? '443' : '80';
1379
- };
1380
- common.hasEncryptedConnection = function(req) {
1381
- return Boolean(req.connection.encrypted || req.connection.pair);
1382
- };
1383
- common.urlJoin = function() {
1384
- var args = Array.prototype.slice.call(arguments), lastIndex = args.length - 1, last = args[lastIndex], lastSegs = last.split('?'), retSegs;
1385
- args[lastIndex] = lastSegs.shift();
1386
- retSegs = [
1387
- args.filter(Boolean).join('/').replace(/\/+/g, '/').replace('http:/', 'http://').replace('https:/', 'https://')
1388
- ];
1389
- retSegs.push.apply(retSegs, lastSegs);
1390
- return retSegs.join('?');
1391
- };
1392
- common.rewriteCookieProperty = function rewriteCookieProperty(header, config, property) {
1393
- if (Array.isArray(header)) return header.map(function(headerElement) {
1394
- return rewriteCookieProperty(headerElement, config, property);
1395
- });
1396
- return header.replace(new RegExp("(;\\s*" + property + "=)([^;]+)", 'i'), function(match, prefix, previousValue) {
1397
- var newValue;
1398
- if (previousValue in config) newValue = config[previousValue];
1399
- else {
1400
- if (!('*' in config)) return match;
1401
- newValue = config['*'];
1402
- }
1403
- if (newValue) return prefix + newValue;
1404
- return '';
1405
- });
1406
- };
1407
- function hasPort(host) {
1408
- return !!~host.indexOf(':');
1409
- }
1410
- },
1411
- "./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/index.js" (module, __unused_rspack_exports, __webpack_require__) {
1412
- var httpProxy = module.exports, extend = __webpack_require__("util")._extend, parse_url = __webpack_require__("url").parse, EE3 = __webpack_require__("./node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.js"), http = __webpack_require__("http"), https = __webpack_require__("https"), web = __webpack_require__("./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js"), ws = __webpack_require__("./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/passes/ws-incoming.js");
1413
- httpProxy.Server = ProxyServer;
1414
- function createRightProxy(type) {
1415
- return function(options) {
1416
- return function(req, res) {
1417
- var passes = 'ws' === type ? this.wsPasses : this.webPasses, args = [].slice.call(arguments), cntr = args.length - 1, head, cbl;
1418
- if ('function' == typeof args[cntr]) {
1419
- cbl = args[cntr];
1420
- cntr--;
1421
- }
1422
- var requestOptions = options;
1423
- if (!(args[cntr] instanceof Buffer) && args[cntr] !== res) {
1424
- requestOptions = extend({}, options);
1425
- extend(requestOptions, args[cntr]);
1426
- cntr--;
1427
- }
1428
- if (args[cntr] instanceof Buffer) head = args[cntr];
1429
- [
1430
- 'target',
1431
- 'forward'
1432
- ].forEach(function(e) {
1433
- if ('string' == typeof requestOptions[e]) requestOptions[e] = parse_url(requestOptions[e]);
1434
- });
1435
- if (!requestOptions.target && !requestOptions.forward) return this.emit('error', new Error('Must provide a proper URL as target'));
1436
- for(var i = 0; i < passes.length && !passes[i](req, res, requestOptions, head, this, cbl); i++);
1437
- };
1438
- };
1439
- }
1440
- httpProxy.createRightProxy = createRightProxy;
1441
- function ProxyServer(options) {
1442
- EE3.call(this);
1443
- options = options || {};
1444
- options.prependPath = false !== options.prependPath;
1445
- this.web = this.proxyRequest = createRightProxy('web')(options);
1446
- this.ws = this.proxyWebsocketRequest = createRightProxy('ws')(options);
1447
- this.options = options;
1448
- this.webPasses = Object.keys(web).map(function(pass) {
1449
- return web[pass];
1450
- });
1451
- this.wsPasses = Object.keys(ws).map(function(pass) {
1452
- return ws[pass];
1453
- });
1454
- this.on('error', this.onError, this);
1455
- }
1456
- __webpack_require__("util").inherits(ProxyServer, EE3);
1457
- ProxyServer.prototype.onError = function(err) {
1458
- if (1 === this.listeners('error').length) throw err;
1459
- };
1460
- ProxyServer.prototype.listen = function(port, hostname) {
1461
- var self = this, closure = function(req, res) {
1462
- self.web(req, res);
1463
- };
1464
- this._server = this.options.ssl ? https.createServer(this.options.ssl, closure) : http.createServer(closure);
1465
- if (this.options.ws) this._server.on('upgrade', function(req, socket, head) {
1466
- self.ws(req, socket, head);
1467
- });
1468
- this._server.listen(port, hostname);
1469
- return this;
1470
- };
1471
- ProxyServer.prototype.close = function(callback) {
1472
- var self = this;
1473
- if (this._server) this._server.close(done);
1474
- function done() {
1475
- self._server = null;
1476
- if (callback) callback.apply(null, arguments);
1477
- }
1478
- };
1479
- ProxyServer.prototype.before = function(type, passName, callback) {
1480
- if ('ws' !== type && 'web' !== type) throw new Error('type must be `web` or `ws`');
1481
- var passes = 'ws' === type ? this.wsPasses : this.webPasses, i = false;
1482
- passes.forEach(function(v, idx) {
1483
- if (v.name === passName) i = idx;
1484
- });
1485
- if (false === i) throw new Error('No such pass');
1486
- passes.splice(i, 0, callback);
1487
- };
1488
- ProxyServer.prototype.after = function(type, passName, callback) {
1489
- if ('ws' !== type && 'web' !== type) throw new Error('type must be `web` or `ws`');
1490
- var passes = 'ws' === type ? this.wsPasses : this.webPasses, i = false;
1491
- passes.forEach(function(v, idx) {
1492
- if (v.name === passName) i = idx;
1493
- });
1494
- if (false === i) throw new Error('No such pass');
1495
- passes.splice(i++, 0, callback);
1496
- };
1497
- },
1498
- "./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js" (module, __unused_rspack_exports, __webpack_require__) {
1499
- var httpNative = __webpack_require__("http"), httpsNative = __webpack_require__("https"), web_o = __webpack_require__("./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/passes/web-outgoing.js"), common = __webpack_require__("./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/common.js"), followRedirects = __webpack_require__("./node_modules/.pnpm/follow-redirects@1.15.11_debug@4.4.3/node_modules/follow-redirects/index.js");
1500
- web_o = Object.keys(web_o).map(function(pass) {
1501
- return web_o[pass];
1502
- });
1503
- var nativeAgents = {
1504
- http: httpNative,
1505
- https: httpsNative
1506
- };
1507
- /*!
1508
- * Array of passes.
1509
- *
1510
- * A `pass` is just a function that is executed on `req, res, options`
1511
- * so that you can easily add new checks while still keeping the base
1512
- * flexible.
1513
- */ module.exports = {
1514
- deleteLength: function(req, res, options) {
1515
- if (('DELETE' === req.method || 'OPTIONS' === req.method) && !req.headers['content-length']) {
1516
- req.headers['content-length'] = '0';
1517
- delete req.headers['transfer-encoding'];
1518
- }
1519
- },
1520
- timeout: function(req, res, options) {
1521
- if (options.timeout) req.socket.setTimeout(options.timeout);
1522
- },
1523
- XHeaders: function(req, res, options) {
1524
- if (!options.xfwd) return;
1525
- var encrypted = req.isSpdy || common.hasEncryptedConnection(req);
1526
- var values = {
1527
- for: req.connection.remoteAddress || req.socket.remoteAddress,
1528
- port: common.getPort(req),
1529
- proto: encrypted ? 'https' : 'http'
1530
- };
1531
- [
1532
- 'for',
1533
- 'port',
1534
- 'proto'
1535
- ].forEach(function(header) {
1536
- req.headers['x-forwarded-' + header] = (req.headers['x-forwarded-' + header] || '') + (req.headers['x-forwarded-' + header] ? ',' : '') + values[header];
1537
- });
1538
- req.headers['x-forwarded-host'] = req.headers['x-forwarded-host'] || req.headers['host'] || '';
1539
- },
1540
- stream: function(req, res, options, _, server, clb) {
1541
- server.emit('start', req, res, options.target || options.forward);
1542
- var agents = options.followRedirects ? followRedirects : nativeAgents;
1543
- var http = agents.http;
1544
- var https = agents.https;
1545
- if (options.forward) {
1546
- var forwardReq = ('https:' === options.forward.protocol ? https : http).request(common.setupOutgoing(options.ssl || {}, options, req, 'forward'));
1547
- var forwardError = createErrorHandler(forwardReq, options.forward);
1548
- req.on('error', forwardError);
1549
- forwardReq.on('error', forwardError);
1550
- (options.buffer || req).pipe(forwardReq);
1551
- if (!options.target) return res.end();
1552
- }
1553
- var proxyReq = ('https:' === options.target.protocol ? https : http).request(common.setupOutgoing(options.ssl || {}, options, req));
1554
- proxyReq.on('socket', function(socket) {
1555
- if (server && !proxyReq.getHeader('expect')) server.emit('proxyReq', proxyReq, req, res, options);
1556
- });
1557
- if (options.proxyTimeout) proxyReq.setTimeout(options.proxyTimeout, function() {
1558
- proxyReq.abort();
1559
- });
1560
- req.on('aborted', function() {
1561
- proxyReq.abort();
1562
- });
1563
- var proxyError = createErrorHandler(proxyReq, options.target);
1564
- req.on('error', proxyError);
1565
- proxyReq.on('error', proxyError);
1566
- function createErrorHandler(proxyReq, url) {
1567
- return function(err) {
1568
- if (req.socket.destroyed && 'ECONNRESET' === err.code) {
1569
- server.emit('econnreset', err, req, res, url);
1570
- return proxyReq.abort();
1571
- }
1572
- if (clb) clb(err, req, res, url);
1573
- else server.emit('error', err, req, res, url);
1574
- };
1575
- }
1576
- (options.buffer || req).pipe(proxyReq);
1577
- proxyReq.on('response', function(proxyRes) {
1578
- if (server) server.emit('proxyRes', proxyRes, req, res);
1579
- if (!res.headersSent && !options.selfHandleResponse) for(var i = 0; i < web_o.length && !web_o[i](req, res, proxyRes, options); i++);
1580
- if (res.finished) {
1581
- if (server) server.emit('end', req, res, proxyRes);
1582
- } else {
1583
- proxyRes.on('end', function() {
1584
- if (server) server.emit('end', req, res, proxyRes);
1585
- });
1586
- if (!options.selfHandleResponse) proxyRes.pipe(res);
1587
- }
1588
- });
1589
- }
1590
- };
1591
- },
1592
- "./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/passes/web-outgoing.js" (module, __unused_rspack_exports, __webpack_require__) {
1593
- var url = __webpack_require__("url"), common = __webpack_require__("./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/common.js");
1594
- var redirectRegex = /^201|30(1|2|7|8)$/;
1595
- /*!
1596
- * Array of passes.
1597
- *
1598
- * A `pass` is just a function that is executed on `req, res, options`
1599
- * so that you can easily add new checks while still keeping the base
1600
- * flexible.
1601
- */ module.exports = {
1602
- removeChunked: function(req, res, proxyRes) {
1603
- if ('1.0' === req.httpVersion) delete proxyRes.headers['transfer-encoding'];
1604
- },
1605
- setConnection: function(req, res, proxyRes) {
1606
- if ('1.0' === req.httpVersion) proxyRes.headers.connection = req.headers.connection || 'close';
1607
- else if ('2.0' !== req.httpVersion && !proxyRes.headers.connection) proxyRes.headers.connection = req.headers.connection || 'keep-alive';
1608
- },
1609
- setRedirectHostRewrite: function(req, res, proxyRes, options) {
1610
- if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite) && proxyRes.headers['location'] && redirectRegex.test(proxyRes.statusCode)) {
1611
- var target = url.parse(options.target);
1612
- var u = url.parse(proxyRes.headers['location']);
1613
- if (target.host != u.host) return;
1614
- if (options.hostRewrite) u.host = options.hostRewrite;
1615
- else if (options.autoRewrite) u.host = req.headers['host'];
1616
- if (options.protocolRewrite) u.protocol = options.protocolRewrite;
1617
- proxyRes.headers['location'] = u.format();
1618
- }
1619
- },
1620
- writeHeaders: function(req, res, proxyRes, options) {
1621
- var rewriteCookieDomainConfig = options.cookieDomainRewrite, rewriteCookiePathConfig = options.cookiePathRewrite, preserveHeaderKeyCase = options.preserveHeaderKeyCase, rawHeaderKeyMap, setHeader = function(key, header) {
1622
- if (void 0 == header) return;
1623
- if (rewriteCookieDomainConfig && 'set-cookie' === key.toLowerCase()) header = common.rewriteCookieProperty(header, rewriteCookieDomainConfig, 'domain');
1624
- if (rewriteCookiePathConfig && 'set-cookie' === key.toLowerCase()) header = common.rewriteCookieProperty(header, rewriteCookiePathConfig, 'path');
1625
- res.setHeader(String(key).trim(), header);
1626
- };
1627
- if ('string' == typeof rewriteCookieDomainConfig) rewriteCookieDomainConfig = {
1628
- '*': rewriteCookieDomainConfig
1629
- };
1630
- if ('string' == typeof rewriteCookiePathConfig) rewriteCookiePathConfig = {
1631
- '*': rewriteCookiePathConfig
1632
- };
1633
- if (preserveHeaderKeyCase && void 0 != proxyRes.rawHeaders) {
1634
- rawHeaderKeyMap = {};
1635
- for(var i = 0; i < proxyRes.rawHeaders.length; i += 2){
1636
- var key = proxyRes.rawHeaders[i];
1637
- rawHeaderKeyMap[key.toLowerCase()] = key;
1638
- }
1639
- }
1640
- Object.keys(proxyRes.headers).forEach(function(key) {
1641
- var header = proxyRes.headers[key];
1642
- if (preserveHeaderKeyCase && rawHeaderKeyMap) key = rawHeaderKeyMap[key] || key;
1643
- setHeader(key, header);
1644
- });
1645
- },
1646
- writeStatusCode: function(req, res, proxyRes) {
1647
- if (proxyRes.statusMessage) {
1648
- res.statusCode = proxyRes.statusCode;
1649
- res.statusMessage = proxyRes.statusMessage;
1650
- } else res.statusCode = proxyRes.statusCode;
1651
- }
1652
- };
1653
- },
1654
- "./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/passes/ws-incoming.js" (module, __unused_rspack_exports, __webpack_require__) {
1655
- var http = __webpack_require__("http"), https = __webpack_require__("https"), common = __webpack_require__("./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/lib/http-proxy/common.js");
1656
- /*!
1657
- * Array of passes.
1658
- *
1659
- * A `pass` is just a function that is executed on `req, socket, options`
1660
- * so that you can easily add new checks while still keeping the base
1661
- * flexible.
1662
- */ module.exports = {
1663
- checkMethodAndHeader: function(req, socket) {
1664
- if ('GET' !== req.method || !req.headers.upgrade) {
1665
- socket.destroy();
1666
- return true;
1667
- }
1668
- if ('websocket' !== req.headers.upgrade.toLowerCase()) {
1669
- socket.destroy();
1670
- return true;
1671
- }
1672
- },
1673
- XHeaders: function(req, socket, options) {
1674
- if (!options.xfwd) return;
1675
- var values = {
1676
- for: req.connection.remoteAddress || req.socket.remoteAddress,
1677
- port: common.getPort(req),
1678
- proto: common.hasEncryptedConnection(req) ? 'wss' : 'ws'
1679
- };
1680
- [
1681
- 'for',
1682
- 'port',
1683
- 'proto'
1684
- ].forEach(function(header) {
1685
- req.headers['x-forwarded-' + header] = (req.headers['x-forwarded-' + header] || '') + (req.headers['x-forwarded-' + header] ? ',' : '') + values[header];
1686
- });
1687
- },
1688
- stream: function(req, socket, options, head, server, clb) {
1689
- var createHttpHeader = function(line, headers) {
1690
- return Object.keys(headers).reduce(function(head, key) {
1691
- var value = headers[key];
1692
- if (!Array.isArray(value)) {
1693
- head.push(key + ': ' + value);
1694
- return head;
1695
- }
1696
- for(var i = 0; i < value.length; i++)head.push(key + ': ' + value[i]);
1697
- return head;
1698
- }, [
1699
- line
1700
- ]).join('\r\n') + '\r\n\r\n';
1701
- };
1702
- common.setupSocket(socket);
1703
- if (head && head.length) socket.unshift(head);
1704
- var proxyReq = (common.isSSL.test(options.target.protocol) ? https : http).request(common.setupOutgoing(options.ssl || {}, options, req));
1705
- if (server) server.emit('proxyReqWs', proxyReq, req, socket, options, head);
1706
- proxyReq.on('error', onOutgoingError);
1707
- proxyReq.on('response', function(res) {
1708
- if (!res.upgrade) {
1709
- socket.write(createHttpHeader('HTTP/' + res.httpVersion + ' ' + res.statusCode + ' ' + res.statusMessage, res.headers));
1710
- res.pipe(socket);
1711
- }
1712
- });
1713
- proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
1714
- proxySocket.on('error', onOutgoingError);
1715
- proxySocket.on('end', function() {
1716
- server.emit('close', proxyRes, proxySocket, proxyHead);
1717
- });
1718
- socket.on('error', function() {
1719
- proxySocket.end();
1720
- });
1721
- common.setupSocket(proxySocket);
1722
- if (proxyHead && proxyHead.length) proxySocket.unshift(proxyHead);
1723
- socket.write(createHttpHeader('HTTP/1.1 101 Switching Protocols', proxyRes.headers));
1724
- proxySocket.pipe(socket).pipe(proxySocket);
1725
- server.emit('open', proxySocket);
1726
- server.emit('proxySocket', proxySocket);
1727
- });
1728
- return proxyReq.end();
1729
- function onOutgoingError(err) {
1730
- if (clb) clb(err, req, socket);
1731
- else server.emit('error', err, req, socket);
1732
- socket.end();
1733
- }
1734
- }
1735
- };
1736
- },
1737
726
  "./node_modules/.pnpm/is-extglob@2.1.1/node_modules/is-extglob/index.js" (module) {
1738
727
  /*!
1739
728
  * is-extglob <https://github.com/jonschlinkert/is-extglob>
@@ -1856,27 +845,6 @@ __webpack_require__.add({
1856
845
  return false;
1857
846
  };
1858
847
  },
1859
- "./node_modules/.pnpm/is-plain-object@5.0.0/node_modules/is-plain-object/dist/is-plain-object.js" (__unused_rspack_module, exports) {
1860
- /*!
1861
- * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
1862
- *
1863
- * Copyright (c) 2014-2017, Jon Schlinkert.
1864
- * Released under the MIT License.
1865
- */ function isObject(o) {
1866
- return '[object Object]' === Object.prototype.toString.call(o);
1867
- }
1868
- function isPlainObject(o) {
1869
- var ctor, prot;
1870
- if (false === isObject(o)) return false;
1871
- ctor = o.constructor;
1872
- if (void 0 === ctor) return true;
1873
- prot = ctor.prototype;
1874
- if (false === isObject(prot)) return false;
1875
- if (false === prot.hasOwnProperty('isPrototypeOf')) return false;
1876
- return true;
1877
- }
1878
- exports.isPlainObject = isPlainObject;
1879
- },
1880
848
  "./node_modules/.pnpm/micromatch@4.0.8/node_modules/micromatch/index.js" (module, __unused_rspack_exports, __webpack_require__) {
1881
849
  const util = __webpack_require__("util");
1882
850
  const braces = __webpack_require__("./node_modules/.pnpm/braces@3.0.3/node_modules/braces/index.js");
@@ -3629,28 +2597,6 @@ __webpack_require__.add({
3629
2597
  return output;
3630
2598
  };
3631
2599
  },
3632
- "./node_modules/.pnpm/requires-port@1.0.0/node_modules/requires-port/index.js" (module) {
3633
- module.exports = function(port, protocol) {
3634
- protocol = protocol.split(':')[0];
3635
- port *= 1;
3636
- if (!port) return false;
3637
- switch(protocol){
3638
- case 'http':
3639
- case 'ws':
3640
- return 80 !== port;
3641
- case 'https':
3642
- case 'wss':
3643
- return 443 !== port;
3644
- case 'ftp':
3645
- return 21 !== port;
3646
- case 'gopher':
3647
- return 70 !== port;
3648
- case 'file':
3649
- return false;
3650
- }
3651
- return 0 !== port;
3652
- };
3653
- },
3654
2600
  "./node_modules/.pnpm/to-regex-range@5.0.1/node_modules/to-regex-range/index.js" (module, __unused_rspack_exports, __webpack_require__) {
3655
2601
  /*!
3656
2602
  * to-regex-range <https://github.com/micromatch/to-regex-range>
@@ -3846,816 +2792,1016 @@ __webpack_require__.add({
3846
2792
  toRegexRange.cache = {};
3847
2793
  toRegexRange.clearCache = ()=>toRegexRange.cache = {};
3848
2794
  module.exports = toRegexRange;
3849
- },
3850
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/configuration.js" (__unused_rspack_module, exports, __webpack_require__) {
3851
- exports.verifyConfig = verifyConfig;
3852
- const errors_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/errors.js");
3853
- function verifyConfig(options) {
3854
- if (!options.target && !options.router) throw new Error(errors_1.ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING);
3855
- }
3856
- },
3857
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/debug.js" (__unused_rspack_module, exports, __webpack_require__) {
3858
- exports.Debug = void 0;
3859
- const createDebug = __webpack_require__("./node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/index.js");
3860
- exports.Debug = createDebug('http-proxy-middleware');
3861
- },
3862
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/errors.js" (__unused_rspack_module, exports) {
3863
- exports.ERRORS = void 0;
3864
- var ERRORS;
3865
- (function(ERRORS) {
3866
- ERRORS["ERR_CONFIG_FACTORY_TARGET_MISSING"] = "[HPM] Missing \"target\" option. Example: {target: \"http://www.example.org\"}";
3867
- ERRORS["ERR_CONTEXT_MATCHER_GENERIC"] = "[HPM] Invalid pathFilter. Expecting something like: \"/api\" or [\"/api\", \"/ajax\"]";
3868
- ERRORS["ERR_CONTEXT_MATCHER_INVALID_ARRAY"] = "[HPM] Invalid pathFilter. Plain paths (e.g. \"/api\") can not be mixed with globs (e.g. \"/api/**\"). Expecting something like: [\"/api\", \"/ajax\"] or [\"/api/**\", \"!**.html\"].";
3869
- ERRORS["ERR_PATH_REWRITER_CONFIG"] = "[HPM] Invalid pathRewrite config. Expecting object with pathRewrite config or a rewrite function";
3870
- })(ERRORS || (exports.ERRORS = ERRORS = {}));
3871
- },
3872
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/factory.js" (__unused_rspack_module, exports, __webpack_require__) {
3873
- Object.defineProperty(exports, "__esModule", {
3874
- value: true
3875
- });
3876
- exports.createProxyMiddleware = createProxyMiddleware;
3877
- const http_proxy_middleware_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/http-proxy-middleware.js");
3878
- function createProxyMiddleware(options) {
3879
- const { middleware } = new http_proxy_middleware_1.HttpProxyMiddleware(options);
3880
- return middleware;
3881
- }
3882
- },
3883
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/get-plugins.js" (__unused_rspack_module, exports, __webpack_require__) {
3884
- exports.getPlugins = getPlugins;
3885
- const default_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/index.js");
3886
- function getPlugins(options) {
3887
- const maybeErrorResponsePlugin = options.on?.error ? [] : [
3888
- default_1.errorResponsePlugin
3889
- ];
3890
- const defaultPlugins = options.ejectPlugins ? [] : [
3891
- default_1.debugProxyErrorsPlugin,
3892
- default_1.proxyEventsPlugin,
3893
- default_1.loggerPlugin,
3894
- ...maybeErrorResponsePlugin
3895
- ];
3896
- const userPlugins = options.plugins ?? [];
3897
- return [
3898
- ...defaultPlugins,
3899
- ...userPlugins
3900
- ];
3901
- }
3902
- },
3903
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/handlers/fix-request-body.js" (__unused_rspack_module, exports, __webpack_require__) {
3904
- Object.defineProperty(exports, "__esModule", {
3905
- value: true
3906
- });
3907
- exports.fixRequestBody = fixRequestBody;
3908
- const querystring = __webpack_require__("querystring");
3909
- function fixRequestBody(proxyReq, req) {
3910
- if (0 !== req.readableLength) return;
3911
- const requestBody = req.body;
3912
- if (!requestBody) return;
3913
- const contentType = proxyReq.getHeader('Content-Type');
3914
- if (!contentType) return;
3915
- const writeBody = (bodyData)=>{
3916
- proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
3917
- proxyReq.write(bodyData);
3918
- };
3919
- if (contentType.includes('application/json') || contentType.includes('+json')) writeBody(JSON.stringify(requestBody));
3920
- else if (contentType.includes('application/x-www-form-urlencoded')) writeBody(querystring.stringify(requestBody));
3921
- else if (contentType.includes('multipart/form-data')) writeBody(handlerFormDataBodyData(contentType, requestBody));
3922
- }
3923
- function handlerFormDataBodyData(contentType, data) {
3924
- const boundary = contentType.replace(/^.*boundary=(.*)$/, '$1');
3925
- let str = '';
3926
- for (const [key, value] of Object.entries(data))str += `--${boundary}\r\nContent-Disposition: form-data; name="${key}"\r\n\r\n${value}\r\n`;
3927
- return str;
3928
- }
3929
- },
3930
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/handlers/index.js" (__unused_rspack_module, exports, __webpack_require__) {
3931
- var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
3932
- if (void 0 === k2) k2 = k;
3933
- var desc = Object.getOwnPropertyDescriptor(m, k);
3934
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
3935
- enumerable: true,
3936
- get: function() {
3937
- return m[k];
3938
- }
3939
- };
3940
- Object.defineProperty(o, k2, desc);
3941
- } : function(o, m, k, k2) {
3942
- if (void 0 === k2) k2 = k;
3943
- o[k2] = m[k];
3944
- });
3945
- var __exportStar = this && this.__exportStar || function(m, exports) {
3946
- for(var p in m)if ("default" !== p && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
3947
- };
3948
- Object.defineProperty(exports, "__esModule", {
3949
- value: true
2795
+ }
2796
+ });
2797
+ const upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
2798
+ const defaultAgents = {
2799
+ http: new node_http.Agent({
2800
+ keepAlive: true,
2801
+ maxSockets: 256,
2802
+ maxFreeSockets: 64
2803
+ }),
2804
+ https: new node_https.Agent({
2805
+ keepAlive: true,
2806
+ maxSockets: 256,
2807
+ maxFreeSockets: 64
2808
+ })
2809
+ };
2810
+ const isSSL = /^https|wss/;
2811
+ const HTTP2_HEADER_BLACKLIST = [
2812
+ ":method",
2813
+ ":path",
2814
+ ":scheme",
2815
+ ":authority"
2816
+ ];
2817
+ function setupOutgoing(outgoing, options, req, forward) {
2818
+ outgoing.port = options[forward || "target"].port || (isSSL.test(options[forward || "target"].protocol ?? "http") ? 443 : 80);
2819
+ for (const e of [
2820
+ "host",
2821
+ "hostname",
2822
+ "socketPath",
2823
+ "pfx",
2824
+ "key",
2825
+ "passphrase",
2826
+ "cert",
2827
+ "ca",
2828
+ "ciphers",
2829
+ "secureProtocol"
2830
+ ]){
2831
+ const value = options[forward || "target"][e];
2832
+ if (void 0 !== value) outgoing[e] = value;
2833
+ }
2834
+ outgoing.method = options.method || req.method;
2835
+ outgoing.headers = {
2836
+ ...req.headers
2837
+ };
2838
+ if (req.headers?.[":authority"]) outgoing.headers.host = req.headers[":authority"];
2839
+ if (options.headers) for (const key of Object.keys(options.headers))outgoing.headers[key] = options.headers[key];
2840
+ if (req.httpVersionMajor > 1) for (const header of HTTP2_HEADER_BLACKLIST)delete outgoing.headers[header];
2841
+ if (options.auth) outgoing.auth = options.auth;
2842
+ if (options.ca) outgoing.ca = options.ca;
2843
+ if (isSSL.test(options[forward || "target"].protocol ?? "http")) outgoing.rejectUnauthorized = void 0 === options.secure ? true : options.secure;
2844
+ if (void 0 !== options.agent) outgoing.agent = options.agent || false;
2845
+ else if (req.httpVersionMajor > 1 || upgradeHeader.test(req.headers.connection || "")) outgoing.agent = false;
2846
+ else {
2847
+ const targetProto = options[forward || "target"].protocol ?? "http";
2848
+ outgoing.agent = isSSL.test(targetProto) ? defaultAgents.https : defaultAgents.http;
2849
+ }
2850
+ outgoing.localAddress = options.localAddress;
2851
+ if (!outgoing.agent) {
2852
+ outgoing.headers = outgoing.headers || {};
2853
+ if ("string" != typeof outgoing.headers.connection || !upgradeHeader.test(outgoing.headers.connection)) outgoing.headers.connection = "close";
2854
+ }
2855
+ const target = options[forward || "target"];
2856
+ const targetPath = target && false !== options.prependPath ? target.pathname || "" : "";
2857
+ const targetSearch = target instanceof URL && false !== options.prependPath ? target.search || "" : "";
2858
+ const reqUrl = req.url || "";
2859
+ const qIdx = reqUrl.indexOf("?");
2860
+ const reqPath = -1 === qIdx ? reqUrl : reqUrl.slice(0, qIdx);
2861
+ const reqSearch = -1 === qIdx ? "" : reqUrl.slice(qIdx);
2862
+ const normalizedPath = reqPath ? "/" === reqPath[0] ? reqPath : "/" + reqPath : "/";
2863
+ let outgoingPath = options.toProxy ? "/" + reqUrl : normalizedPath + reqSearch;
2864
+ outgoingPath = options.ignorePath ? "" : outgoingPath;
2865
+ let fullPath = joinURL(targetPath, outgoingPath);
2866
+ if (targetSearch) fullPath = fullPath.includes("?") ? fullPath.replace("?", targetSearch + "&") : fullPath + targetSearch;
2867
+ outgoing.path = fullPath;
2868
+ if (options.changeOrigin) outgoing.headers.host = requiresPort(outgoing.port, options[forward || "target"].protocol) && !hasPort(outgoing.host) ? outgoing.host + ":" + outgoing.port : outgoing.host ?? void 0;
2869
+ return outgoing;
2870
+ }
2871
+ function joinURL(base, path) {
2872
+ if (!base || "/" === base) return path || "/";
2873
+ if (!path || "/" === path) return base || "/";
2874
+ const baseHasTrailing = "/" === base[base.length - 1];
2875
+ const pathHasLeading = "/" === path[0];
2876
+ if (baseHasTrailing && pathHasLeading) return base + path.slice(1);
2877
+ if (!baseHasTrailing && !pathHasLeading) return base + "/" + path;
2878
+ return base + path;
2879
+ }
2880
+ function setupSocket(socket) {
2881
+ socket.setTimeout(0);
2882
+ socket.setNoDelay(true);
2883
+ socket.setKeepAlive(true, 0);
2884
+ return socket;
2885
+ }
2886
+ function getPort(req) {
2887
+ const hostHeader = req.headers[":authority"] || req.headers.host;
2888
+ const res = hostHeader ? hostHeader.match(/:(\d+)/) : "";
2889
+ if (res) return res[1];
2890
+ return hasEncryptedConnection(req) ? "443" : "80";
2891
+ }
2892
+ function hasEncryptedConnection(req) {
2893
+ const socket = req.socket;
2894
+ return !!socket && "encrypted" in socket && socket.encrypted;
2895
+ }
2896
+ function rewriteCookieProperty(header, config, property) {
2897
+ if (Array.isArray(header)) return header.map(function(headerElement) {
2898
+ return rewriteCookieProperty(headerElement, config, property);
2899
+ });
2900
+ return header.replace(new RegExp(String.raw`(;\s*` + property + "=)([^;]+)", "i"), function(match, prefix, previousValue) {
2901
+ let newValue;
2902
+ if (previousValue in config) newValue = config[previousValue];
2903
+ else {
2904
+ if (!("*" in config)) return match;
2905
+ newValue = config["*"];
2906
+ }
2907
+ return newValue ? prefix + newValue : "";
2908
+ });
2909
+ }
2910
+ function hasPort(host) {
2911
+ return host ? !!~host.indexOf(":") : false;
2912
+ }
2913
+ function requiresPort(_port, _protocol) {
2914
+ const protocol = _protocol?.split(":")[0];
2915
+ const port = +_port;
2916
+ if (!port) return false;
2917
+ switch(protocol){
2918
+ case "http":
2919
+ case "ws":
2920
+ return 80 !== port;
2921
+ case "https":
2922
+ case "wss":
2923
+ return 443 !== port;
2924
+ case "ftp":
2925
+ return 21 !== port;
2926
+ case "gopher":
2927
+ return 70 !== port;
2928
+ case "file":
2929
+ return false;
2930
+ }
2931
+ return 0 !== port;
2932
+ }
2933
+ function defineProxyMiddleware(m) {
2934
+ return m;
2935
+ }
2936
+ function defineProxyOutgoingMiddleware(m) {
2937
+ return m;
2938
+ }
2939
+ const redirectRegex = /^201|30([12378])$/;
2940
+ const webOutgoingMiddleware = [
2941
+ defineProxyOutgoingMiddleware((req, res, proxyRes)=>{
2942
+ if ("1.0" === req.httpVersion || req.httpVersionMajor >= 2 || 204 === proxyRes.statusCode || 304 === proxyRes.statusCode) delete proxyRes.headers["transfer-encoding"];
2943
+ }),
2944
+ defineProxyOutgoingMiddleware((req, res, proxyRes)=>{
2945
+ if ("1.0" === req.httpVersion) proxyRes.headers.connection = req.headers.connection || "close";
2946
+ else if (req.httpVersionMajor < 2 && !proxyRes.headers.connection) proxyRes.headers.connection = req.headers.connection || "keep-alive";
2947
+ else if (req.httpVersionMajor >= 2) delete proxyRes.headers.connection;
2948
+ }),
2949
+ defineProxyOutgoingMiddleware((req, res, proxyRes, options)=>{
2950
+ if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite) && proxyRes.headers.location && redirectRegex.test(String(proxyRes.statusCode))) {
2951
+ const target = _toURL(options.target);
2952
+ const u = new URL(proxyRes.headers.location, target);
2953
+ if (target.host !== u.host) return;
2954
+ if (options.hostRewrite) u.host = options.hostRewrite;
2955
+ else if (options.autoRewrite) {
2956
+ if (req.headers[":authority"]) u.host = req.headers[":authority"];
2957
+ else if (req.headers.host) u.host = req.headers.host;
2958
+ }
2959
+ if (options.protocolRewrite) u.protocol = options.protocolRewrite;
2960
+ proxyRes.headers.location = u.toString();
2961
+ }
2962
+ }),
2963
+ defineProxyOutgoingMiddleware((req, res, proxyRes, options)=>{
2964
+ const rewriteCookieDomainConfig = "string" == typeof options.cookieDomainRewrite ? {
2965
+ "*": options.cookieDomainRewrite
2966
+ } : options.cookieDomainRewrite;
2967
+ const rewriteCookiePathConfig = "string" == typeof options.cookiePathRewrite ? {
2968
+ "*": options.cookiePathRewrite
2969
+ } : options.cookiePathRewrite;
2970
+ const preserveHeaderKeyCase = options.preserveHeaderKeyCase;
2971
+ let rawHeaderKeyMap;
2972
+ const setHeader = function(key, header) {
2973
+ if (void 0 === header || !String(key).trim()) return;
2974
+ if (rewriteCookieDomainConfig && "set-cookie" === key.toLowerCase()) header = rewriteCookieProperty(header, rewriteCookieDomainConfig, "domain");
2975
+ if (rewriteCookiePathConfig && "set-cookie" === key.toLowerCase()) header = rewriteCookieProperty(header, rewriteCookiePathConfig, "path");
2976
+ try {
2977
+ res.setHeader(String(key).trim(), header);
2978
+ } catch {}
2979
+ };
2980
+ if (preserveHeaderKeyCase && void 0 !== proxyRes.rawHeaders) {
2981
+ rawHeaderKeyMap = {};
2982
+ for(let i = 0; i < proxyRes.rawHeaders.length; i += 2){
2983
+ const key = proxyRes.rawHeaders[i];
2984
+ rawHeaderKeyMap[key.toLowerCase()] = key;
2985
+ }
2986
+ }
2987
+ for (let key of Object.keys(proxyRes.headers)){
2988
+ const header = proxyRes.headers[key];
2989
+ if (preserveHeaderKeyCase && rawHeaderKeyMap) key = rawHeaderKeyMap[key] || key;
2990
+ setHeader(key, header);
2991
+ }
2992
+ }),
2993
+ defineProxyOutgoingMiddleware((req, res, proxyRes)=>{
2994
+ res.statusCode = proxyRes.statusCode;
2995
+ if (proxyRes.statusMessage && req.httpVersionMajor < 2) res.statusMessage = proxyRes.statusMessage;
2996
+ })
2997
+ ];
2998
+ function _toURL(target) {
2999
+ if (target instanceof URL) return target;
3000
+ if ("string" == typeof target) return new URL(target);
3001
+ const protocol = target.protocol || "http:";
3002
+ const host = target.host || target.hostname || "localhost";
3003
+ const port = target.port;
3004
+ return new URL(`${protocol}//${host}${port ? ":" + port : ""}`);
3005
+ }
3006
+ const nativeAgents = {
3007
+ http: node_http,
3008
+ https: node_https
3009
+ };
3010
+ const redirectStatuses = new Set([
3011
+ 301,
3012
+ 302,
3013
+ 303,
3014
+ 307,
3015
+ 308
3016
+ ]);
3017
+ const webIncomingMiddleware = [
3018
+ defineProxyMiddleware((req)=>{
3019
+ if (("DELETE" === req.method || "OPTIONS" === req.method) && !req.headers["content-length"]) {
3020
+ req.headers["content-length"] = "0";
3021
+ delete req.headers["transfer-encoding"];
3022
+ }
3023
+ }),
3024
+ defineProxyMiddleware((req, res, options)=>{
3025
+ if (options.timeout) req.socket.setTimeout(options.timeout, ()=>{
3026
+ req.socket.destroy();
3950
3027
  });
3951
- __exportStar(__webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/handlers/public.js"), exports);
3952
- },
3953
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/handlers/public.js" (__unused_rspack_module, exports, __webpack_require__) {
3954
- Object.defineProperty(exports, "__esModule", {
3955
- value: true
3028
+ }),
3029
+ defineProxyMiddleware((req, res, options)=>{
3030
+ if (!options.xfwd) return;
3031
+ const encrypted = req.isSpdy || hasEncryptedConnection(req);
3032
+ const values = {
3033
+ for: req.connection.remoteAddress || req.socket.remoteAddress,
3034
+ port: getPort(req),
3035
+ proto: encrypted ? "https" : "http"
3036
+ };
3037
+ for (const header of [
3038
+ "for",
3039
+ "port",
3040
+ "proto"
3041
+ ]){
3042
+ const key = "x-forwarded-" + header;
3043
+ if (!req.headers[key] && void 0 !== values[header]) req.headers[key] = values[header];
3044
+ }
3045
+ req.headers["x-forwarded-host"] = req.headers["x-forwarded-host"] || req.headers[":authority"] || req.headers.host || "";
3046
+ }),
3047
+ defineProxyMiddleware((req, res, options, server, head, callback)=>{
3048
+ server.emit("start", req, res, options.target || options.forward);
3049
+ const http = nativeAgents.http;
3050
+ const https = nativeAgents.https;
3051
+ const maxRedirects = "number" == typeof options.followRedirects ? options.followRedirects : options.followRedirects ? 5 : 0;
3052
+ if (options.forward) {
3053
+ const forwardReq = (isSSL.test(options.forward.protocol || "http") ? https : http).request(setupOutgoing(options.ssl || {}, options, req, "forward"));
3054
+ const forwardError = createErrorHandler(forwardReq, options.forward);
3055
+ req.on("error", forwardError);
3056
+ forwardReq.on("error", forwardError);
3057
+ (options.buffer || req).pipe(forwardReq);
3058
+ if (!options.target) return void res.end();
3059
+ }
3060
+ const proxyReq = (isSSL.test(options.target.protocol || "http") ? https : http).request(setupOutgoing(options.ssl || {}, options, req));
3061
+ proxyReq.on("socket", (_socket)=>{
3062
+ if (server && !proxyReq.getHeader("expect")) server.emit("proxyReq", proxyReq, req, res, options);
3956
3063
  });
3957
- exports.fixRequestBody = exports.responseInterceptor = void 0;
3958
- var response_interceptor_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/handlers/response-interceptor.js");
3959
- Object.defineProperty(exports, "responseInterceptor", {
3960
- enumerable: true,
3961
- get: function() {
3962
- return response_interceptor_1.responseInterceptor;
3963
- }
3064
+ if (options.proxyTimeout) proxyReq.setTimeout(options.proxyTimeout, function() {
3065
+ proxyReq.destroy();
3964
3066
  });
3965
- var fix_request_body_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/handlers/fix-request-body.js");
3966
- Object.defineProperty(exports, "fixRequestBody", {
3967
- enumerable: true,
3968
- get: function() {
3969
- return fix_request_body_1.fixRequestBody;
3970
- }
3067
+ res.on("close", function() {
3068
+ if (!res.writableFinished) proxyReq.destroy();
3971
3069
  });
3972
- },
3973
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/handlers/response-interceptor.js" (__unused_rspack_module, exports, __webpack_require__) {
3974
- Object.defineProperty(exports, "__esModule", {
3975
- value: true
3070
+ const proxyError = createErrorHandler(proxyReq, options.target);
3071
+ req.on("error", proxyError);
3072
+ proxyReq.on("error", proxyError);
3073
+ function createErrorHandler(proxyReq, url) {
3074
+ return function(err) {
3075
+ if (!req.socket?.writable && "ECONNRESET" === err.code) {
3076
+ server.emit("econnreset", err, req, res, url);
3077
+ return proxyReq.destroy();
3078
+ }
3079
+ if (callback) callback(err, req, res, url);
3080
+ else server.emit("error", err, req, res, url);
3081
+ };
3082
+ }
3083
+ let bodyBuffer;
3084
+ if (maxRedirects > 0) {
3085
+ const chunks = [];
3086
+ const source = options.buffer || req;
3087
+ source.on("data", (chunk)=>{
3088
+ chunks.push("string" == typeof chunk ? Buffer.from(chunk) : chunk);
3089
+ proxyReq.write(chunk);
3090
+ });
3091
+ source.on("end", ()=>{
3092
+ bodyBuffer = Buffer.concat(chunks);
3093
+ proxyReq.end();
3094
+ });
3095
+ source.on("error", (err)=>{
3096
+ proxyReq.destroy(err);
3097
+ });
3098
+ } else proxyReq.on("socket", (socket)=>{
3099
+ if (socket.pending) socket.on("connect", ()=>(options.buffer || req).pipe(proxyReq));
3100
+ else (options.buffer || req).pipe(proxyReq);
3976
3101
  });
3977
- exports.responseInterceptor = responseInterceptor;
3978
- const zlib = __webpack_require__("zlib");
3979
- const debug_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/debug.js");
3980
- const function_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/utils/function.js");
3981
- const debug = debug_1.Debug.extend('response-interceptor');
3982
- function responseInterceptor(interceptor) {
3983
- return async function(proxyRes, req, res) {
3984
- debug('intercept proxy response');
3985
- const originalProxyRes = proxyRes;
3986
- let buffer = Buffer.from('', 'utf8');
3987
- const _proxyRes = decompress(proxyRes, proxyRes.headers['content-encoding']);
3988
- _proxyRes.on('data', (chunk)=>buffer = Buffer.concat([
3989
- buffer,
3990
- chunk
3991
- ]));
3992
- _proxyRes.on('end', async ()=>{
3993
- copyHeaders(proxyRes, res);
3994
- debug('call interceptor function: %s', (0, function_1.getFunctionName)(interceptor));
3995
- const interceptedBuffer = Buffer.from(await interceptor(buffer, originalProxyRes, req, res));
3996
- debug('set content-length: %s', Buffer.byteLength(interceptedBuffer, 'utf8'));
3997
- res.setHeader('content-length', Buffer.byteLength(interceptedBuffer, 'utf8'));
3998
- debug('write intercepted response');
3999
- res.write(interceptedBuffer);
4000
- res.end();
3102
+ function handleResponse(proxyRes, redirectCount, currentUrl) {
3103
+ const statusCode = proxyRes.statusCode;
3104
+ if (maxRedirects > 0 && redirectStatuses.has(statusCode) && redirectCount < maxRedirects && proxyRes.headers.location) {
3105
+ proxyRes.resume();
3106
+ const location = new URL(proxyRes.headers.location, currentUrl);
3107
+ const preserveMethod = 307 === statusCode || 308 === statusCode;
3108
+ const redirectMethod = preserveMethod ? req.method || "GET" : "GET";
3109
+ const isHTTPS = isSSL.test(location.protocol);
3110
+ const agent = isHTTPS ? https : http;
3111
+ const redirectHeaders = {
3112
+ ...req.headers
3113
+ };
3114
+ if (options.headers) Object.assign(redirectHeaders, options.headers);
3115
+ redirectHeaders.host = location.host;
3116
+ if (location.host !== currentUrl.host) {
3117
+ delete redirectHeaders.authorization;
3118
+ delete redirectHeaders.cookie;
3119
+ }
3120
+ if (!preserveMethod) {
3121
+ delete redirectHeaders["content-length"];
3122
+ delete redirectHeaders["content-type"];
3123
+ delete redirectHeaders["transfer-encoding"];
3124
+ }
3125
+ const redirectOpts = {
3126
+ hostname: location.hostname,
3127
+ port: location.port || (isHTTPS ? 443 : 80),
3128
+ path: location.pathname + location.search,
3129
+ method: redirectMethod,
3130
+ headers: redirectHeaders,
3131
+ agent: options.agent || false
3132
+ };
3133
+ if (isHTTPS) redirectOpts.rejectUnauthorized = void 0 === options.secure ? true : options.secure;
3134
+ const redirectReq = agent.request(redirectOpts);
3135
+ if (server && !redirectReq.getHeader("expect")) server.emit("proxyReq", redirectReq, req, res, options);
3136
+ if (options.proxyTimeout) redirectReq.setTimeout(options.proxyTimeout, ()=>{
3137
+ redirectReq.destroy();
4001
3138
  });
4002
- _proxyRes.on('error', (error)=>{
4003
- res.end(`Error fetching proxied request: ${error.message}`);
3139
+ const redirectError = createErrorHandler(redirectReq, location);
3140
+ redirectReq.on("error", redirectError);
3141
+ redirectReq.on("response", (nextRes)=>{
3142
+ handleResponse(nextRes, redirectCount + 1, location);
4004
3143
  });
4005
- };
4006
- }
4007
- function decompress(proxyRes, contentEncoding) {
4008
- let _proxyRes = proxyRes;
4009
- let decompress;
4010
- switch(contentEncoding){
4011
- case 'gzip':
4012
- decompress = zlib.createGunzip();
4013
- break;
4014
- case 'br':
4015
- decompress = zlib.createBrotliDecompress();
4016
- break;
4017
- case 'deflate':
4018
- decompress = zlib.createInflate();
4019
- break;
4020
- default:
4021
- break;
3144
+ if (preserveMethod && bodyBuffer && bodyBuffer.length > 0) redirectReq.end(bodyBuffer);
3145
+ else redirectReq.end();
3146
+ return;
4022
3147
  }
4023
- if (decompress) {
4024
- debug("decompress proxy response with 'content-encoding': %s", contentEncoding);
4025
- _proxyRes.pipe(decompress);
4026
- _proxyRes = decompress;
3148
+ if (server) server.emit("proxyRes", proxyRes, req, res);
3149
+ if (!res.headersSent && !options.selfHandleResponse) {
3150
+ for (const pass of webOutgoingMiddleware)if (pass(req, res, proxyRes, options)) break;
4027
3151
  }
4028
- return _proxyRes;
4029
- }
4030
- function copyHeaders(originalResponse, response) {
4031
- debug('copy original response headers');
4032
- response.statusCode = originalResponse.statusCode;
4033
- response.statusMessage = originalResponse.statusMessage;
4034
- if (response.setHeader) {
4035
- let keys = Object.keys(originalResponse.headers);
4036
- keys = keys.filter((key)=>![
4037
- 'content-encoding',
4038
- 'transfer-encoding'
4039
- ].includes(key));
4040
- keys.forEach((key)=>{
4041
- let value = originalResponse.headers[key];
4042
- if ('set-cookie' === key) {
4043
- value = Array.isArray(value) ? value : [
4044
- value
4045
- ];
4046
- value = value.map((x)=>x.replace(/Domain=[^;]+?/i, ''));
4047
- }
4048
- response.setHeader(key, value);
3152
+ if (res.finished) {
3153
+ if (server) server.emit("end", req, res, proxyRes);
3154
+ } else {
3155
+ res.on("close", function() {
3156
+ proxyRes.destroy();
4049
3157
  });
4050
- } else response.headers = originalResponse.headers;
4051
- }
4052
- },
4053
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/http-proxy-middleware.js" (__unused_rspack_module, exports, __webpack_require__) {
4054
- exports.HttpProxyMiddleware = void 0;
4055
- const httpProxy = __webpack_require__("./node_modules/.pnpm/http-proxy@1.18.1_debug@4.4.3/node_modules/http-proxy/index.js");
4056
- const configuration_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/configuration.js");
4057
- const get_plugins_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/get-plugins.js");
4058
- const path_filter_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/path-filter.js");
4059
- const PathRewriter = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/path-rewriter.js");
4060
- const Router = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/router.js");
4061
- const debug_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/debug.js");
4062
- const function_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/utils/function.js");
4063
- const logger_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/logger.js");
4064
- class HttpProxyMiddleware {
4065
- constructor(options){
4066
- this.wsInternalSubscribed = false;
4067
- this.serverOnCloseSubscribed = false;
4068
- this.middleware = async (req, res, next)=>{
4069
- if (this.shouldProxy(this.proxyOptions.pathFilter, req)) try {
4070
- const activeProxyOptions = await this.prepareProxyRequest(req);
4071
- (0, debug_1.Debug)("proxy request to target: %O", activeProxyOptions.target);
4072
- this.proxy.web(req, res, activeProxyOptions);
4073
- } catch (err) {
4074
- next?.(err);
4075
- }
4076
- else next?.();
4077
- const server = (req.socket ?? req.connection)?.server;
4078
- if (server && !this.serverOnCloseSubscribed) {
4079
- server.on('close', ()=>{
4080
- (0, debug_1.Debug)('server close signal received: closing proxy server');
4081
- this.proxy.close();
4082
- });
4083
- this.serverOnCloseSubscribed = true;
4084
- }
4085
- if (true === this.proxyOptions.ws) this.catchUpgradeRequest(server);
4086
- };
4087
- this.catchUpgradeRequest = (server)=>{
4088
- if (!this.wsInternalSubscribed) {
4089
- (0, debug_1.Debug)('subscribing to server upgrade event');
4090
- server.on('upgrade', this.handleUpgrade);
4091
- this.wsInternalSubscribed = true;
4092
- }
4093
- };
4094
- this.handleUpgrade = async (req, socket, head)=>{
4095
- try {
4096
- if (this.shouldProxy(this.proxyOptions.pathFilter, req)) {
4097
- const activeProxyOptions = await this.prepareProxyRequest(req);
4098
- this.proxy.ws(req, socket, head, activeProxyOptions);
4099
- (0, debug_1.Debug)('server upgrade event received. Proxying WebSocket');
4100
- }
4101
- } catch (err) {
4102
- this.proxy.emit('error', err, req, socket);
4103
- }
4104
- };
4105
- this.shouldProxy = (pathFilter, req)=>{
4106
- try {
4107
- return (0, path_filter_1.matchPathFilter)(pathFilter, req.url, req);
4108
- } catch (err) {
4109
- (0, debug_1.Debug)('Error: matchPathFilter() called with request url: ', `"${req.url}"`);
4110
- this.logger.error(err);
4111
- return false;
4112
- }
4113
- };
4114
- this.prepareProxyRequest = async (req)=>{
4115
- if (this.middleware.__LEGACY_HTTP_PROXY_MIDDLEWARE__) req.url = req.originalUrl || req.url;
4116
- const newProxyOptions = Object.assign({}, this.proxyOptions);
4117
- await this.applyRouter(req, newProxyOptions);
4118
- await this.applyPathRewrite(req, this.pathRewriter);
4119
- return newProxyOptions;
4120
- };
4121
- this.applyRouter = async (req, options)=>{
4122
- let newTarget;
4123
- if (options.router) {
4124
- newTarget = await Router.getTarget(req, options);
4125
- if (newTarget) {
4126
- (0, debug_1.Debug)('router new target: "%s"', newTarget);
4127
- options.target = newTarget;
4128
- }
4129
- }
4130
- };
4131
- this.applyPathRewrite = async (req, pathRewriter)=>{
4132
- if (pathRewriter) {
4133
- const path = await pathRewriter(req.url, req);
4134
- if ('string' == typeof path) {
4135
- (0, debug_1.Debug)('pathRewrite new path: %s', req.url);
4136
- req.url = path;
4137
- } else (0, debug_1.Debug)('pathRewrite: no rewritten path found: %s', req.url);
4138
- }
4139
- };
4140
- (0, configuration_1.verifyConfig)(options);
4141
- this.proxyOptions = options;
4142
- this.logger = (0, logger_1.getLogger)(options);
4143
- (0, debug_1.Debug)("create proxy server");
4144
- this.proxy = httpProxy.createProxyServer({});
4145
- this.registerPlugins(this.proxy, this.proxyOptions);
4146
- this.pathRewriter = PathRewriter.createPathRewriter(this.proxyOptions.pathRewrite);
4147
- this.middleware.upgrade = (req, socket, head)=>{
4148
- if (!this.wsInternalSubscribed) this.handleUpgrade(req, socket, head);
4149
- };
4150
- }
4151
- registerPlugins(proxy, options) {
4152
- const plugins = (0, get_plugins_1.getPlugins)(options);
4153
- plugins.forEach((plugin)=>{
4154
- (0, debug_1.Debug)(`register plugin: "${(0, function_1.getFunctionName)(plugin)}"`);
4155
- plugin(proxy, options);
3158
+ proxyRes.on("close", function() {
3159
+ if (!proxyRes.complete && !res.destroyed) res.destroy();
3160
+ });
3161
+ proxyRes.on("error", function(err) {
3162
+ if (!res.destroyed) res.destroy(err);
3163
+ if (server.listenerCount("error") > 0) server.emit("error", err, req, res, currentUrl);
3164
+ });
3165
+ proxyRes.on("end", function() {
3166
+ if (server) server.emit("end", req, res, proxyRes);
4156
3167
  });
3168
+ if (!options.selfHandleResponse) proxyRes.pipe(res);
4157
3169
  }
4158
3170
  }
4159
- exports.HttpProxyMiddleware = HttpProxyMiddleware;
4160
- },
4161
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/index.js" (__unused_rspack_module, exports, __webpack_require__) {
4162
- var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4163
- if (void 0 === k2) k2 = k;
4164
- var desc = Object.getOwnPropertyDescriptor(m, k);
4165
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
4166
- enumerable: true,
4167
- get: function() {
4168
- return m[k];
4169
- }
4170
- };
4171
- Object.defineProperty(o, k2, desc);
4172
- } : function(o, m, k, k2) {
4173
- if (void 0 === k2) k2 = k;
4174
- o[k2] = m[k];
3171
+ proxyReq.on("response", function(proxyRes) {
3172
+ handleResponse(proxyRes, 0, options.target);
4175
3173
  });
4176
- var __exportStar = this && this.__exportStar || function(m, exports) {
4177
- for(var p in m)if ("default" !== p && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
3174
+ })
3175
+ ];
3176
+ const websocketIncomingMiddleware = [
3177
+ defineProxyMiddleware((req, socket)=>{
3178
+ if ("GET" !== req.method || !req.headers.upgrade) {
3179
+ socket.destroy();
3180
+ return true;
3181
+ }
3182
+ if ("websocket" !== req.headers.upgrade.toLowerCase()) {
3183
+ socket.destroy();
3184
+ return true;
3185
+ }
3186
+ }),
3187
+ defineProxyMiddleware((req, socket, options)=>{
3188
+ if (!options.xfwd) return;
3189
+ const values = {
3190
+ for: req.connection.remoteAddress || req.socket.remoteAddress,
3191
+ port: getPort(req),
3192
+ proto: hasEncryptedConnection(req) ? "wss" : "ws"
4178
3193
  };
4179
- Object.defineProperty(exports, "__esModule", {
4180
- value: true
3194
+ for (const header of [
3195
+ "for",
3196
+ "port",
3197
+ "proto"
3198
+ ]){
3199
+ const key = "x-forwarded-" + header;
3200
+ if (!req.headers[key] && void 0 !== values[header]) req.headers[key] = values[header];
3201
+ }
3202
+ }),
3203
+ defineProxyMiddleware((req, socket, options, server, head, callback)=>{
3204
+ const createHttpHeader = function(line, headers) {
3205
+ return Object.keys(headers).reduce(function(head, key) {
3206
+ const value = headers[key];
3207
+ if (!Array.isArray(value)) {
3208
+ head.push(key + ": " + value);
3209
+ return head;
3210
+ }
3211
+ for (const element of value)head.push(key + ": " + element);
3212
+ return head;
3213
+ }, [
3214
+ line
3215
+ ]).join("\r\n") + "\r\n\r\n";
3216
+ };
3217
+ setupSocket(socket);
3218
+ if (head && head.length > 0) socket.unshift(head);
3219
+ socket.on("error", onSocketError);
3220
+ const proxyReq = (isSSL.test(options.target.protocol || "http") ? node_https : node_http).request(setupOutgoing(options.ssl || {}, options, req));
3221
+ if (server) server.emit("proxyReqWs", proxyReq, req, socket, options, head);
3222
+ proxyReq.on("error", onOutgoingError);
3223
+ proxyReq.on("response", function(res) {
3224
+ if (!res.upgrade) if (!socket.destroyed && socket.writable) {
3225
+ socket.write(createHttpHeader("HTTP/" + res.httpVersion + " " + res.statusCode + " " + res.statusMessage, res.headers));
3226
+ res.on("error", onOutgoingError);
3227
+ res.pipe(socket);
3228
+ } else res.resume();
4181
3229
  });
4182
- __exportStar(__webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/factory.js"), exports);
4183
- __exportStar(__webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/handlers/index.js"), exports);
4184
- __exportStar(__webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/index.js"), exports);
4185
- __exportStar(__webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/legacy/index.js"), exports);
4186
- },
4187
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/legacy/create-proxy-middleware.js" (__unused_rspack_module, exports, __webpack_require__) {
4188
- Object.defineProperty(exports, "__esModule", {
4189
- value: true
3230
+ proxyReq.on("upgrade", function(proxyRes, proxySocket, proxyHead) {
3231
+ proxySocket.on("error", onOutgoingError);
3232
+ proxySocket.on("end", function() {
3233
+ server.emit("close", proxyRes, proxySocket, proxyHead);
3234
+ });
3235
+ socket.removeListener("error", onSocketError);
3236
+ socket.on("error", function() {
3237
+ proxySocket.end();
3238
+ });
3239
+ setupSocket(proxySocket);
3240
+ if (proxyHead && proxyHead.length > 0) proxySocket.unshift(proxyHead);
3241
+ socket.write(createHttpHeader("HTTP/1.1 101 Switching Protocols", proxyRes.headers));
3242
+ proxySocket.pipe(socket).pipe(proxySocket);
3243
+ server.emit("open", proxySocket);
3244
+ server.emit("proxySocket", proxySocket);
4190
3245
  });
4191
- exports.legacyCreateProxyMiddleware = legacyCreateProxyMiddleware;
4192
- const factory_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/factory.js");
4193
- const debug_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/debug.js");
4194
- const options_adapter_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/legacy/options-adapter.js");
4195
- const debug = debug_1.Debug.extend('legacy-create-proxy-middleware');
4196
- function legacyCreateProxyMiddleware(legacyContext, legacyOptions) {
4197
- debug('init');
4198
- const options = (0, options_adapter_1.legacyOptionsAdapter)(legacyContext, legacyOptions);
4199
- const proxyMiddleware = (0, factory_1.createProxyMiddleware)(options);
4200
- debug('add marker for patching req.url (old behavior)');
4201
- proxyMiddleware.__LEGACY_HTTP_PROXY_MIDDLEWARE__ = true;
4202
- return proxyMiddleware;
4203
- }
4204
- },
4205
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/legacy/index.js" (__unused_rspack_module, exports, __webpack_require__) {
4206
- var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4207
- if (void 0 === k2) k2 = k;
4208
- var desc = Object.getOwnPropertyDescriptor(m, k);
4209
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
4210
- enumerable: true,
4211
- get: function() {
4212
- return m[k];
4213
- }
4214
- };
4215
- Object.defineProperty(o, k2, desc);
4216
- } : function(o, m, k, k2) {
4217
- if (void 0 === k2) k2 = k;
4218
- o[k2] = m[k];
3246
+ proxyReq.end();
3247
+ function onSocketError(err) {
3248
+ if (callback) callback(err, req, socket);
3249
+ else server.emit("error", err, req, socket);
3250
+ proxyReq.destroy();
3251
+ }
3252
+ function onOutgoingError(err) {
3253
+ if (callback) callback(err, req, socket);
3254
+ else server.emit("error", err, req, socket);
3255
+ socket.end();
3256
+ }
3257
+ })
3258
+ ];
3259
+ var ProxyServer = class extends EventEmitter {
3260
+ _server;
3261
+ _webPasses = [
3262
+ ...webIncomingMiddleware
3263
+ ];
3264
+ _wsPasses = [
3265
+ ...websocketIncomingMiddleware
3266
+ ];
3267
+ options;
3268
+ web;
3269
+ ws;
3270
+ constructor(options = {}){
3271
+ super();
3272
+ this.options = options || {};
3273
+ this.options.prependPath = false !== options.prependPath;
3274
+ this.web = _createProxyFn("web", this);
3275
+ this.ws = _createProxyFn("ws", this);
3276
+ }
3277
+ listen(port, hostname, listeningListener) {
3278
+ const closure = (req, res)=>this.web(req, res);
3279
+ if (this.options.http2) {
3280
+ if (!this.options.ssl) throw new Error("HTTP/2 requires ssl option");
3281
+ this._server = node_http2.createSecureServer({
3282
+ ...this.options.ssl,
3283
+ allowHTTP1: true
3284
+ }, closure);
3285
+ } else if (this.options.ssl) this._server = node_https.createServer(this.options.ssl, closure);
3286
+ else this._server = node_http.createServer(closure);
3287
+ if (this.options.ws) this._server.on("upgrade", (req, socket, head)=>{
3288
+ this.ws(req, socket, this.options, head).catch(()=>{});
4219
3289
  });
4220
- var __exportStar = this && this.__exportStar || function(m, exports) {
4221
- for(var p in m)if ("default" !== p && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4222
- };
4223
- Object.defineProperty(exports, "__esModule", {
4224
- value: true
3290
+ this._server.listen(port, hostname, listeningListener);
3291
+ return this;
3292
+ }
3293
+ close(callback) {
3294
+ if (this._server) this._server.close((...args)=>{
3295
+ this._server = void 0;
3296
+ if (callback) Reflect.apply(callback, void 0, args);
4225
3297
  });
4226
- __exportStar(__webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/legacy/public.js"), exports);
4227
- },
4228
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/legacy/options-adapter.js" (__unused_rspack_module, exports, __webpack_require__) {
4229
- exports.legacyOptionsAdapter = legacyOptionsAdapter;
4230
- const url = __webpack_require__("url");
4231
- const debug_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/debug.js");
4232
- const logger_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/logger.js");
4233
- const debug = debug_1.Debug.extend('legacy-options-adapter');
4234
- const proxyEventMap = {
4235
- onError: 'error',
4236
- onProxyReq: 'proxyReq',
4237
- onProxyRes: 'proxyRes',
4238
- onProxyReqWs: 'proxyReqWs',
4239
- onOpen: 'open',
4240
- onClose: 'close'
4241
- };
4242
- function legacyOptionsAdapter(legacyContext, legacyOptions) {
4243
- let options = {};
4244
- let logger;
4245
- if ('string' == typeof legacyContext && !!url.parse(legacyContext).host) throw new Error(`Shorthand syntax is removed from legacyCreateProxyMiddleware().
4246
- Please use "legacyCreateProxyMiddleware({ target: 'http://www.example.org' })" instead.
4247
-
4248
- More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#removed-shorthand-usage
4249
- `);
4250
- if (legacyContext && legacyOptions) {
4251
- debug('map legacy context/filter to options.pathFilter');
4252
- options = {
4253
- ...legacyOptions,
4254
- pathFilter: legacyContext
4255
- };
4256
- logger = getLegacyLogger(options);
4257
- logger.warn(`[http-proxy-middleware] Legacy "context" argument is deprecated. Migrate your "context" to "options.pathFilter":
4258
-
4259
- const options = {
4260
- pathFilter: '${legacyContext}',
4261
- }
4262
-
4263
- More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#removed-context-argument
4264
- `);
4265
- } else if (legacyContext && !legacyOptions) {
4266
- options = {
4267
- ...legacyContext
4268
- };
4269
- logger = getLegacyLogger(options);
4270
- } else logger = getLegacyLogger({});
4271
- Object.entries(proxyEventMap).forEach(([legacyEventName, proxyEventName])=>{
4272
- if (options[legacyEventName]) {
4273
- options.on = {
4274
- ...options.on
4275
- };
4276
- options.on[proxyEventName] = options[legacyEventName];
4277
- debug('map legacy event "%s" to "on.%s"', legacyEventName, proxyEventName);
4278
- logger.warn(`[http-proxy-middleware] Legacy "${legacyEventName}" is deprecated. Migrate to "options.on.${proxyEventName}":
4279
-
4280
- const options = {
4281
- on: {
4282
- ${proxyEventName}: () => {},
4283
- },
4284
- }
4285
-
4286
- More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#refactored-proxy-events
4287
- `);
4288
- }
4289
- });
4290
- const logProvider = options.logProvider && options.logProvider();
4291
- const logLevel = options.logLevel;
4292
- debug('legacy logLevel', logLevel);
4293
- debug('legacy logProvider: %O', logProvider);
4294
- if ('string' == typeof logLevel && 'silent' !== logLevel) {
4295
- debug('map "logProvider" to "logger"');
4296
- logger.warn(`[http-proxy-middleware] Legacy "logLevel" and "logProvider" are deprecated. Migrate to "options.logger":
4297
-
4298
- const options = {
4299
- logger: console,
4300
- }
4301
-
4302
- More details: https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md#removed-logprovider-and-loglevel-options
4303
- `);
4304
- }
4305
- return options;
4306
- }
4307
- function getLegacyLogger(options) {
4308
- const legacyLogger = options.logProvider && options.logProvider();
4309
- if (legacyLogger) options.logger = legacyLogger;
4310
- return (0, logger_1.getLogger)(options);
4311
- }
4312
- },
4313
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/legacy/public.js" (__unused_rspack_module, exports, __webpack_require__) {
4314
- Object.defineProperty(exports, "__esModule", {
4315
- value: true
3298
+ }
3299
+ before(type, passName, pass) {
3300
+ if ("ws" !== type && "web" !== type) throw new Error("type must be `web` or `ws`");
3301
+ const passes = this._getPasses(type);
3302
+ let i = false;
3303
+ for (const [idx, v] of passes.entries())if (v.name === passName) i = idx;
3304
+ if (false === i) throw new Error("No such pass");
3305
+ passes.splice(i, 0, pass);
3306
+ }
3307
+ after(type, passName, pass) {
3308
+ if ("ws" !== type && "web" !== type) throw new Error("type must be `web` or `ws`");
3309
+ const passes = this._getPasses(type);
3310
+ let i = false;
3311
+ for (const [idx, v] of passes.entries())if (v.name === passName) i = idx;
3312
+ if (false === i) throw new Error("No such pass");
3313
+ passes.splice(i++, 0, pass);
3314
+ }
3315
+ _getPasses(type) {
3316
+ return "ws" === type ? this._wsPasses : this._webPasses;
3317
+ }
3318
+ };
3319
+ function createProxyServer(options = {}) {
3320
+ return new ProxyServer(options);
3321
+ }
3322
+ function _createProxyFn(type, server) {
3323
+ return function(req, res, opts, head) {
3324
+ const requestOptions = {
3325
+ ...opts,
3326
+ ...server.options
3327
+ };
3328
+ for (const key of [
3329
+ "target",
3330
+ "forward"
3331
+ ])if ("string" == typeof requestOptions[key]) requestOptions[key] = new URL(requestOptions[key]);
3332
+ if (!requestOptions.target && !requestOptions.forward) {
3333
+ this.emit("error", /* @__PURE__ */ new Error("Must provide a proper URL as target"));
3334
+ return Promise.resolve();
3335
+ }
3336
+ let _resolve;
3337
+ let _reject;
3338
+ const callbackPromise = new Promise((resolve, reject)=>{
3339
+ _resolve = resolve;
3340
+ _reject = reject;
4316
3341
  });
4317
- exports.legacyCreateProxyMiddleware = void 0;
4318
- var create_proxy_middleware_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/legacy/create-proxy-middleware.js");
4319
- Object.defineProperty(exports, "legacyCreateProxyMiddleware", {
4320
- enumerable: true,
4321
- get: function() {
4322
- return create_proxy_middleware_1.legacyCreateProxyMiddleware;
4323
- }
3342
+ res.on("close", ()=>{
3343
+ _resolve();
4324
3344
  });
4325
- },
4326
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/logger.js" (__unused_rspack_module, exports) {
4327
- exports.getLogger = getLogger;
4328
- const noopLogger = {
4329
- info: ()=>{},
4330
- warn: ()=>{},
4331
- error: ()=>{}
4332
- };
4333
- function getLogger(options) {
4334
- return options.logger || noopLogger;
4335
- }
4336
- },
4337
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/path-filter.js" (__unused_rspack_module, exports, __webpack_require__) {
4338
- exports.matchPathFilter = matchPathFilter;
4339
- const isGlob = __webpack_require__("./node_modules/.pnpm/is-glob@4.0.3/node_modules/is-glob/index.js");
4340
- const micromatch = __webpack_require__("./node_modules/.pnpm/micromatch@4.0.8/node_modules/micromatch/index.js");
4341
- const url = __webpack_require__("url");
4342
- const errors_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/errors.js");
4343
- function matchPathFilter(pathFilter = '/', uri, req) {
4344
- if (isStringPath(pathFilter)) return matchSingleStringPath(pathFilter, uri);
4345
- if (isGlobPath(pathFilter)) return matchSingleGlobPath(pathFilter, uri);
4346
- if (Array.isArray(pathFilter)) {
4347
- if (pathFilter.every(isStringPath)) return matchMultiPath(pathFilter, uri);
4348
- if (pathFilter.every(isGlobPath)) return matchMultiGlobPath(pathFilter, uri);
4349
- throw new Error(errors_1.ERRORS.ERR_CONTEXT_MATCHER_INVALID_ARRAY);
4350
- }
4351
- if ('function' == typeof pathFilter) {
4352
- const pathname = getUrlPathName(uri);
4353
- return pathFilter(pathname, req);
4354
- }
4355
- throw new Error(errors_1.ERRORS.ERR_CONTEXT_MATCHER_GENERIC);
4356
- }
4357
- function matchSingleStringPath(pathFilter, uri) {
4358
- const pathname = getUrlPathName(uri);
4359
- return pathname?.indexOf(pathFilter) === 0;
4360
- }
4361
- function matchSingleGlobPath(pattern, uri) {
4362
- const pathname = getUrlPathName(uri);
4363
- const matches = micromatch([
4364
- pathname
4365
- ], pattern);
4366
- return matches && matches.length > 0;
4367
- }
4368
- function matchMultiGlobPath(patternList, uri) {
4369
- return matchSingleGlobPath(patternList, uri);
4370
- }
4371
- function matchMultiPath(pathFilterList, uri) {
4372
- let isMultiPath = false;
4373
- for (const context of pathFilterList)if (matchSingleStringPath(context, uri)) {
4374
- isMultiPath = true;
3345
+ res.on("error", (error)=>{
3346
+ _reject(error);
3347
+ });
3348
+ for (const pass of server._getPasses(type)){
3349
+ let stop;
3350
+ try {
3351
+ stop = pass(req, res, requestOptions, server, head, (error)=>{
3352
+ if (server.listenerCount("error") > 0) {
3353
+ server.emit("error", error, req, res);
3354
+ _resolve();
3355
+ } else _reject(error);
3356
+ });
3357
+ } catch (error) {
3358
+ if (server.listenerCount("error") > 0) {
3359
+ server.emit("error", error, req, res);
3360
+ _resolve();
3361
+ } else _reject(error);
4375
3362
  break;
4376
3363
  }
4377
- return isMultiPath;
4378
- }
4379
- function getUrlPathName(uri) {
4380
- return uri && url.parse(uri).pathname;
4381
- }
4382
- function isStringPath(pathFilter) {
4383
- return 'string' == typeof pathFilter && !isGlob(pathFilter);
4384
- }
4385
- function isGlobPath(pathFilter) {
4386
- return isGlob(pathFilter);
4387
- }
4388
- },
4389
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/path-rewriter.js" (__unused_rspack_module, exports, __webpack_require__) {
4390
- exports.createPathRewriter = createPathRewriter;
4391
- const is_plain_object_1 = __webpack_require__("./node_modules/.pnpm/is-plain-object@5.0.0/node_modules/is-plain-object/dist/is-plain-object.js");
4392
- const errors_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/errors.js");
4393
- const debug_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/debug.js");
4394
- const debug = debug_1.Debug.extend('path-rewriter');
4395
- function createPathRewriter(rewriteConfig) {
4396
- let rulesCache;
4397
- if (!isValidRewriteConfig(rewriteConfig)) return;
4398
- if ('function' == typeof rewriteConfig) {
4399
- const customRewriteFn = rewriteConfig;
4400
- return customRewriteFn;
4401
- }
4402
- rulesCache = parsePathRewriteRules(rewriteConfig);
4403
- return rewritePath;
4404
- function rewritePath(path) {
4405
- let result = path;
4406
- for (const rule of rulesCache)if (rule.regex.test(path)) {
4407
- result = result.replace(rule.regex, rule.value);
4408
- debug('rewriting path from "%s" to "%s"', path, result);
4409
- break;
4410
- }
4411
- return result;
3364
+ if (stop) {
3365
+ _resolve();
3366
+ break;
4412
3367
  }
4413
3368
  }
4414
- function isValidRewriteConfig(rewriteConfig) {
4415
- if ('function' == typeof rewriteConfig) return true;
4416
- if ((0, is_plain_object_1.isPlainObject)(rewriteConfig)) return 0 !== Object.keys(rewriteConfig).length;
4417
- if (null == rewriteConfig) return false;
4418
- throw new Error(errors_1.ERRORS.ERR_PATH_REWRITER_CONFIG);
4419
- }
4420
- function parsePathRewriteRules(rewriteConfig) {
4421
- const rules = [];
4422
- if ((0, is_plain_object_1.isPlainObject)(rewriteConfig)) for (const [key, value] of Object.entries(rewriteConfig)){
4423
- rules.push({
4424
- regex: new RegExp(key),
4425
- value: value
4426
- });
4427
- debug('rewrite rule created: "%s" ~> "%s"', key, value);
3369
+ return callbackPromise;
3370
+ };
3371
+ }
3372
+ new Set([
3373
+ 301,
3374
+ 302,
3375
+ 303,
3376
+ 307,
3377
+ 308
3378
+ ]);
3379
+ var errors_ERRORS;
3380
+ (function(ERRORS) {
3381
+ ERRORS["ERR_CONFIG_FACTORY_TARGET_MISSING"] = "[HPM] Missing \"target\" option. Example: {target: \"http://www.example.org\"}";
3382
+ ERRORS["ERR_CONTEXT_MATCHER_GENERIC"] = "[HPM] Invalid pathFilter. Expecting something like: \"/api\" or [\"/api\", \"/ajax\"]";
3383
+ ERRORS["ERR_CONTEXT_MATCHER_INVALID_ARRAY"] = "[HPM] Invalid pathFilter. Plain paths (e.g. \"/api\") can not be mixed with globs (e.g. \"/api/**\"). Expecting something like: [\"/api\", \"/ajax\"] or [\"/api/**\", \"!**.html\"].";
3384
+ ERRORS["ERR_PATH_REWRITER_CONFIG"] = "[HPM] Invalid pathRewrite config. Expecting object with pathRewrite config or a rewrite function";
3385
+ })(errors_ERRORS || (errors_ERRORS = {}));
3386
+ function verifyConfig(options) {
3387
+ if (!options.target && !options.router) throw new Error(errors_ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING);
3388
+ }
3389
+ const src = __webpack_require__("./node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/index.js");
3390
+ const Debug = src('http-proxy-middleware');
3391
+ const debug = Debug.extend('debug-proxy-errors-plugin');
3392
+ const debugProxyErrorsPlugin = (proxyServer)=>{
3393
+ proxyServer.on('error', (error, req, res, target)=>{
3394
+ debug(`http-proxy error event: \n%O`, error);
3395
+ });
3396
+ proxyServer.on('proxyReq', (proxyReq, req, socket)=>{
3397
+ socket.on('error', (error)=>{
3398
+ debug('Socket error in proxyReq event: \n%O', error);
3399
+ });
3400
+ });
3401
+ proxyServer.on('proxyRes', (proxyRes, req, res)=>{
3402
+ res.on('close', ()=>{
3403
+ if (!res.writableEnded) {
3404
+ debug('Destroying proxyRes in proxyRes close event');
3405
+ proxyRes.destroy();
4428
3406
  }
4429
- return rules;
4430
- }
4431
- },
4432
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/debug-proxy-errors-plugin.js" (__unused_rspack_module, exports, __webpack_require__) {
4433
- Object.defineProperty(exports, "__esModule", {
4434
- value: true
4435
3407
  });
4436
- exports.debugProxyErrorsPlugin = void 0;
4437
- const debug_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/debug.js");
4438
- const debug = debug_1.Debug.extend('debug-proxy-errors-plugin');
4439
- const debugProxyErrorsPlugin = (proxyServer)=>{
4440
- proxyServer.on('error', (error, req, res, target)=>{
4441
- debug(`http-proxy error event: \n%O`, error);
4442
- });
4443
- proxyServer.on('proxyReq', (proxyReq, req, socket)=>{
4444
- socket.on('error', (error)=>{
4445
- debug('Socket error in proxyReq event: \n%O', error);
4446
- });
4447
- });
4448
- proxyServer.on('proxyRes', (proxyRes, req, res)=>{
4449
- res.on('close', ()=>{
4450
- if (!res.writableEnded) {
4451
- debug('Destroying proxyRes in proxyRes close event');
4452
- proxyRes.destroy();
4453
- }
4454
- });
4455
- });
4456
- proxyServer.on('proxyReqWs', (proxyReq, req, socket)=>{
4457
- socket.on('error', (error)=>{
4458
- debug('Socket error in proxyReqWs event: \n%O', error);
4459
- });
4460
- });
4461
- proxyServer.on('open', (proxySocket)=>{
4462
- proxySocket.on('error', (error)=>{
4463
- debug('Socket error in open event: \n%O', error);
4464
- });
4465
- });
4466
- proxyServer.on('close', (req, socket, head)=>{
4467
- socket.on('error', (error)=>{
4468
- debug('Socket error in close event: \n%O', error);
4469
- });
4470
- });
4471
- proxyServer.on('econnreset', (error, req, res, target)=>{
4472
- debug(`http-proxy econnreset event: \n%O`, error);
4473
- });
4474
- };
4475
- exports.debugProxyErrorsPlugin = debugProxyErrorsPlugin;
4476
- },
4477
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/error-response-plugin.js" (__unused_rspack_module, exports, __webpack_require__) {
4478
- Object.defineProperty(exports, "__esModule", {
4479
- value: true
3408
+ });
3409
+ proxyServer.on('proxyReqWs', (proxyReq, req, socket)=>{
3410
+ socket.on('error', (error)=>{
3411
+ debug('Socket error in proxyReqWs event: \n%O', error);
4480
3412
  });
4481
- exports.errorResponsePlugin = void 0;
4482
- const status_code_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/status-code.js");
4483
- function isResponseLike(obj) {
4484
- return obj && 'function' == typeof obj.writeHead;
4485
- }
4486
- function isSocketLike(obj) {
4487
- return obj && 'function' == typeof obj.write && !('writeHead' in obj);
4488
- }
4489
- const errorResponsePlugin = (proxyServer, options)=>{
4490
- proxyServer.on('error', (err, req, res, target)=>{
4491
- if (!req && !res) throw err;
4492
- if (isResponseLike(res)) {
4493
- if (!res.headersSent) {
4494
- const statusCode = (0, status_code_1.getStatusCode)(err.code);
4495
- res.writeHead(statusCode);
4496
- }
4497
- const host = req.headers && req.headers.host;
4498
- res.end(`Error occurred while trying to proxy: ${host}${req.url}`);
4499
- } else if (isSocketLike(res)) res.destroy();
4500
- });
4501
- };
4502
- exports.errorResponsePlugin = errorResponsePlugin;
4503
- },
4504
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/index.js" (__unused_rspack_module, exports, __webpack_require__) {
4505
- var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4506
- if (void 0 === k2) k2 = k;
4507
- var desc = Object.getOwnPropertyDescriptor(m, k);
4508
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
4509
- enumerable: true,
4510
- get: function() {
4511
- return m[k];
4512
- }
4513
- };
4514
- Object.defineProperty(o, k2, desc);
4515
- } : function(o, m, k, k2) {
4516
- if (void 0 === k2) k2 = k;
4517
- o[k2] = m[k];
3413
+ });
3414
+ proxyServer.on('open', (proxySocket)=>{
3415
+ proxySocket.on('error', (error)=>{
3416
+ debug('Socket error in open event: \n%O', error);
4518
3417
  });
4519
- var __exportStar = this && this.__exportStar || function(m, exports) {
4520
- for(var p in m)if ("default" !== p && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4521
- };
4522
- Object.defineProperty(exports, "__esModule", {
4523
- value: true
3418
+ });
3419
+ proxyServer.on('close', (req, socket, head)=>{
3420
+ socket.on('error', (error)=>{
3421
+ debug('Socket error in close event: \n%O', error);
4524
3422
  });
4525
- __exportStar(__webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/debug-proxy-errors-plugin.js"), exports);
4526
- __exportStar(__webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/error-response-plugin.js"), exports);
4527
- __exportStar(__webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/logger-plugin.js"), exports);
4528
- __exportStar(__webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/proxy-events.js"), exports);
4529
- },
4530
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/logger-plugin.js" (__unused_rspack_module, exports, __webpack_require__) {
4531
- Object.defineProperty(exports, "__esModule", {
4532
- value: true
3423
+ });
3424
+ proxyServer.on('econnreset', (error, req, res, target)=>{
3425
+ debug(`http-proxy econnreset event: \n%O`, error);
3426
+ });
3427
+ };
3428
+ function getStatusCode(errorCode) {
3429
+ let statusCode;
3430
+ if (/HPE_INVALID/.test(errorCode)) statusCode = 502;
3431
+ else switch(errorCode){
3432
+ case 'ECONNRESET':
3433
+ case 'ENOTFOUND':
3434
+ case 'ECONNREFUSED':
3435
+ case 'ETIMEDOUT':
3436
+ statusCode = 504;
3437
+ break;
3438
+ default:
3439
+ statusCode = 500;
3440
+ break;
3441
+ }
3442
+ return statusCode;
3443
+ }
3444
+ function sanitize(input) {
3445
+ return input?.replace(/[<>]/g, (i)=>encodeURIComponent(i)) ?? '';
3446
+ }
3447
+ function isResponseLike(obj) {
3448
+ return obj && 'function' == typeof obj.writeHead;
3449
+ }
3450
+ function isSocketLike(obj) {
3451
+ return obj && 'function' == typeof obj.write && !('writeHead' in obj);
3452
+ }
3453
+ const errorResponsePlugin = (proxyServer, options)=>{
3454
+ proxyServer.on('error', (err, req, res, target)=>{
3455
+ if (!req || !res) throw err;
3456
+ if (isResponseLike(res)) {
3457
+ if (!res.headersSent) {
3458
+ const statusCode = getStatusCode(err.code);
3459
+ res.writeHead(statusCode);
3460
+ }
3461
+ const host = req.headers && req.headers.host;
3462
+ res.end(`Error occurred while trying to proxy: ${sanitize(host)}${sanitize(req.url)}`);
3463
+ } else if (isSocketLike(res)) res.destroy();
3464
+ });
3465
+ };
3466
+ const noopLogger = {
3467
+ info: ()=>{},
3468
+ warn: ()=>{},
3469
+ error: ()=>{}
3470
+ };
3471
+ function logger_getLogger(options) {
3472
+ return options.logger || noopLogger;
3473
+ }
3474
+ function logger_plugin_getPort(sockets) {
3475
+ return Object.keys(sockets || {})?.[0]?.split(':')[1];
3476
+ }
3477
+ const loggerPlugin = (proxyServer, options)=>{
3478
+ const logger = logger_getLogger(options);
3479
+ proxyServer.on('error', (err, req, res, target)=>{
3480
+ const hostname = req?.headers?.host;
3481
+ const requestHref = `${hostname}${req?.url}`;
3482
+ const targetHref = `${target?.href}`;
3483
+ const errorMessage = '[HPM] Error occurred while proxying request %s to %s [%s] (%s)';
3484
+ const errReference = 'https://nodejs.org/api/errors.html#errors_common_system_errors';
3485
+ logger.error(errorMessage, requestHref, targetHref, err.code || err, errReference);
3486
+ });
3487
+ proxyServer.on('proxyRes', (proxyRes, req, res)=>{
3488
+ const originalUrl = req.originalUrl ?? `${req.baseUrl || ''}${req.url}`;
3489
+ let target;
3490
+ try {
3491
+ const port = logger_plugin_getPort(proxyRes.req?.agent?.sockets);
3492
+ const obj = {
3493
+ protocol: proxyRes.req.protocol,
3494
+ host: proxyRes.req.host,
3495
+ pathname: proxyRes.req.path
3496
+ };
3497
+ target = new external_node_url_URL(`${obj.protocol}//${obj.host}${obj.pathname}`);
3498
+ if (port) target.port = port;
3499
+ } catch (err) {
3500
+ target = new external_node_url_URL(options.target);
3501
+ target.pathname = proxyRes.req.path;
3502
+ }
3503
+ const targetUrl = target.toString();
3504
+ const exchange = `[HPM] ${req.method} ${originalUrl} -> ${targetUrl} [${proxyRes.statusCode}]`;
3505
+ logger.info(exchange);
3506
+ });
3507
+ proxyServer.on('open', (socket)=>{
3508
+ logger.info('[HPM] Client connected: %o', socket.address());
3509
+ });
3510
+ proxyServer.on('close', (req, proxySocket, proxyHead)=>{
3511
+ logger.info('[HPM] Client disconnected: %o', proxySocket.address());
3512
+ });
3513
+ };
3514
+ function function_getFunctionName(fn) {
3515
+ return fn.name || '[anonymous Function]';
3516
+ }
3517
+ const proxy_events_debug = Debug.extend('proxy-events-plugin');
3518
+ const proxyEventsPlugin = (proxyServer, options)=>{
3519
+ if (!options.on) return;
3520
+ let eventName;
3521
+ for(eventName in options.on)if (Object.prototype.hasOwnProperty.call(options.on, eventName)) {
3522
+ const handler = options.on[eventName];
3523
+ if (!handler) continue;
3524
+ proxy_events_debug(`register event handler: "${eventName}" -> "${function_getFunctionName(handler)}"`);
3525
+ proxyServer.on(eventName, handler);
3526
+ }
3527
+ };
3528
+ function getPlugins(options) {
3529
+ const maybeErrorResponsePlugin = options.on?.error ? [] : [
3530
+ errorResponsePlugin
3531
+ ];
3532
+ const defaultPlugins = options.ejectPlugins ? [] : [
3533
+ debugProxyErrorsPlugin,
3534
+ proxyEventsPlugin,
3535
+ loggerPlugin,
3536
+ ...maybeErrorResponsePlugin
3537
+ ];
3538
+ const userPlugins = options.plugins ?? [];
3539
+ return [
3540
+ ...defaultPlugins,
3541
+ ...userPlugins
3542
+ ];
3543
+ }
3544
+ const is_glob = __webpack_require__("./node_modules/.pnpm/is-glob@4.0.3/node_modules/is-glob/index.js");
3545
+ const micromatch = __webpack_require__("./node_modules/.pnpm/micromatch@4.0.8/node_modules/micromatch/index.js");
3546
+ function matchPathFilter(pathFilter = '/', uri, req) {
3547
+ if (isStringPath(pathFilter)) return matchSingleStringPath(pathFilter, uri);
3548
+ if (isGlobPath(pathFilter)) return matchSingleGlobPath(pathFilter, uri);
3549
+ if (Array.isArray(pathFilter)) {
3550
+ if (pathFilter.every(isStringPath)) return matchMultiPath(pathFilter, uri);
3551
+ if (pathFilter.every(isGlobPath)) return matchMultiGlobPath(pathFilter, uri);
3552
+ throw new Error(errors_ERRORS.ERR_CONTEXT_MATCHER_INVALID_ARRAY);
3553
+ }
3554
+ if ('function' == typeof pathFilter) {
3555
+ const pathname = getUrlPathName(uri);
3556
+ return pathFilter(pathname, req);
3557
+ }
3558
+ throw new Error(errors_ERRORS.ERR_CONTEXT_MATCHER_GENERIC);
3559
+ }
3560
+ function matchSingleStringPath(pathFilter, uri) {
3561
+ const pathname = getUrlPathName(uri);
3562
+ return pathname?.indexOf(pathFilter) === 0;
3563
+ }
3564
+ function matchSingleGlobPath(pattern, uri) {
3565
+ const pathname = getUrlPathName(uri);
3566
+ const matches = micromatch([
3567
+ pathname
3568
+ ], pattern);
3569
+ return matches && matches.length > 0;
3570
+ }
3571
+ function matchMultiGlobPath(patternList, uri) {
3572
+ return matchSingleGlobPath(patternList, uri);
3573
+ }
3574
+ function matchMultiPath(pathFilterList, uri) {
3575
+ let isMultiPath = false;
3576
+ for (const context of pathFilterList)if (matchSingleStringPath(context, uri)) {
3577
+ isMultiPath = true;
3578
+ break;
3579
+ }
3580
+ return isMultiPath;
3581
+ }
3582
+ function getUrlPathName(uri) {
3583
+ return uri && new URL(uri, 'http://0.0.0.0').pathname;
3584
+ }
3585
+ function isStringPath(pathFilter) {
3586
+ return 'string' == typeof pathFilter && !is_glob(pathFilter);
3587
+ }
3588
+ function isGlobPath(pathFilter) {
3589
+ return is_glob(pathFilter);
3590
+ }
3591
+ function isPlainObject(value) {
3592
+ if ('object' != typeof value || null === value) return false;
3593
+ const prototype = Object.getPrototypeOf(value);
3594
+ return (null === prototype || prototype === Object.prototype || null === Object.getPrototypeOf(prototype)) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
3595
+ }
3596
+ const path_rewriter_debug = Debug.extend('path-rewriter');
3597
+ function createPathRewriter(rewriteConfig) {
3598
+ let rulesCache;
3599
+ if (!isValidRewriteConfig(rewriteConfig)) return;
3600
+ if ('function' == typeof rewriteConfig) {
3601
+ const customRewriteFn = rewriteConfig;
3602
+ return customRewriteFn;
3603
+ }
3604
+ rulesCache = parsePathRewriteRules(rewriteConfig);
3605
+ return rewritePath;
3606
+ function rewritePath(path) {
3607
+ let result = path;
3608
+ for (const rule of rulesCache)if (rule.regex.test(path)) {
3609
+ result = result.replace(rule.regex, rule.value);
3610
+ path_rewriter_debug('rewriting path from "%s" to "%s"', path, result);
3611
+ break;
3612
+ }
3613
+ return result;
3614
+ }
3615
+ }
3616
+ function isValidRewriteConfig(rewriteConfig) {
3617
+ if ('function' == typeof rewriteConfig) return true;
3618
+ if (isPlainObject(rewriteConfig)) return 0 !== Object.keys(rewriteConfig).length;
3619
+ if (null == rewriteConfig) return false;
3620
+ throw new Error(errors_ERRORS.ERR_PATH_REWRITER_CONFIG);
3621
+ }
3622
+ function parsePathRewriteRules(rewriteConfig) {
3623
+ const rules = [];
3624
+ if (isPlainObject(rewriteConfig)) for (const [key, value] of Object.entries(rewriteConfig)){
3625
+ rules.push({
3626
+ regex: new RegExp(key),
3627
+ value: value
4533
3628
  });
4534
- exports.loggerPlugin = void 0;
4535
- const url_1 = __webpack_require__("url");
4536
- const logger_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/logger.js");
4537
- const logger_plugin_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/utils/logger-plugin.js");
4538
- const loggerPlugin = (proxyServer, options)=>{
4539
- const logger = (0, logger_1.getLogger)(options);
4540
- proxyServer.on('error', (err, req, res, target)=>{
4541
- const hostname = req?.headers?.host;
4542
- const requestHref = `${hostname}${req?.url}`;
4543
- const targetHref = `${target?.href}`;
4544
- const errorMessage = '[HPM] Error occurred while proxying request %s to %s [%s] (%s)';
4545
- const errReference = 'https://nodejs.org/api/errors.html#errors_common_system_errors';
4546
- logger.error(errorMessage, requestHref, targetHref, err.code || err, errReference);
4547
- });
4548
- proxyServer.on('proxyRes', (proxyRes, req, res)=>{
4549
- const originalUrl = req.originalUrl ?? `${req.baseUrl || ''}${req.url}`;
4550
- let target;
4551
- try {
4552
- const port = (0, logger_plugin_1.getPort)(proxyRes.req?.agent?.sockets);
4553
- const obj = {
4554
- protocol: proxyRes.req.protocol,
4555
- host: proxyRes.req.host,
4556
- pathname: proxyRes.req.path
4557
- };
4558
- target = new url_1.URL(`${obj.protocol}//${obj.host}${obj.pathname}`);
4559
- if (port) target.port = port;
4560
- } catch (err) {
4561
- target = new url_1.URL(options.target);
4562
- target.pathname = proxyRes.req.path;
4563
- }
4564
- const targetUrl = target.toString();
4565
- const exchange = `[HPM] ${req.method} ${originalUrl} -> ${targetUrl} [${proxyRes.statusCode}]`;
4566
- logger.info(exchange);
4567
- });
4568
- proxyServer.on('open', (socket)=>{
4569
- logger.info('[HPM] Client connected: %o', socket.address());
4570
- });
4571
- proxyServer.on('close', (req, proxySocket, proxyHead)=>{
4572
- logger.info('[HPM] Client disconnected: %o', proxySocket.address());
4573
- });
3629
+ path_rewriter_debug('rewrite rule created: "%s" ~> "%s"', key, value);
3630
+ }
3631
+ return rules;
3632
+ }
3633
+ const router_debug = Debug.extend('router');
3634
+ async function getTarget(req, config) {
3635
+ let newTarget;
3636
+ const router = config.router;
3637
+ if (isPlainObject(router)) newTarget = getTargetFromProxyTable(req, router);
3638
+ else if ('function' == typeof router) newTarget = await router(req);
3639
+ return newTarget;
3640
+ }
3641
+ function getTargetFromProxyTable(req, table) {
3642
+ let result;
3643
+ const host = req.headers.host ?? '';
3644
+ const path = req.url ?? '';
3645
+ const hostAndPath = host + path;
3646
+ for (const [key, value] of Object.entries(table))if (containsPath(key)) {
3647
+ if (hostAndPath.indexOf(key) > -1) {
3648
+ result = value;
3649
+ router_debug('match: "%s" -> "%s"', key, result);
3650
+ break;
3651
+ }
3652
+ } else if (key === host) {
3653
+ result = value;
3654
+ router_debug('match: "%s" -> "%s"', host, result);
3655
+ break;
3656
+ }
3657
+ return result;
3658
+ }
3659
+ function containsPath(v) {
3660
+ return v.indexOf('/') > -1;
3661
+ }
3662
+ const ipv6_debug = Debug.extend('ipv6');
3663
+ function normalizeIPv6LiteralTargets(options) {
3664
+ options.target = normalizeIPv6ProxyTarget(options.target, 'target');
3665
+ options.forward = normalizeIPv6ProxyTarget(options.forward, 'forward');
3666
+ }
3667
+ function normalizeIPv6ProxyTarget(target, optionName) {
3668
+ const targetUrl = toTargetUrl(target);
3669
+ if (targetUrl && isBracketedIPv6Hostname(targetUrl.hostname)) {
3670
+ ipv6_debug('normalized IPv6 "%s" %s', optionName, target);
3671
+ return {
3672
+ hostname: stripBrackets(targetUrl.hostname),
3673
+ pathname: targetUrl.pathname,
3674
+ port: targetUrl.port,
3675
+ protocol: targetUrl.protocol,
3676
+ search: targetUrl.search
4574
3677
  };
4575
- exports.loggerPlugin = loggerPlugin;
4576
- },
4577
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/plugins/default/proxy-events.js" (__unused_rspack_module, exports, __webpack_require__) {
4578
- Object.defineProperty(exports, "__esModule", {
4579
- value: true
4580
- });
4581
- exports.proxyEventsPlugin = void 0;
4582
- const debug_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/debug.js");
4583
- const function_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/utils/function.js");
4584
- const debug = debug_1.Debug.extend('proxy-events-plugin');
4585
- const proxyEventsPlugin = (proxyServer, options)=>{
4586
- Object.entries(options.on || {}).forEach(([eventName, handler])=>{
4587
- debug(`register event handler: "${eventName}" -> "${(0, function_1.getFunctionName)(handler)}"`);
4588
- proxyServer.on(eventName, handler);
4589
- });
3678
+ }
3679
+ return target;
3680
+ }
3681
+ function toTargetUrl(target) {
3682
+ if ('string' == typeof target) return new URL(target);
3683
+ if (target instanceof URL) return target;
3684
+ }
3685
+ function isBracketedIPv6Hostname(hostname) {
3686
+ return hostname.startsWith('[') && hostname.endsWith(']');
3687
+ }
3688
+ function stripBrackets(hostname) {
3689
+ return hostname.replace(/^\[|\]$/g, '');
3690
+ }
3691
+ class HttpProxyMiddleware {
3692
+ wsInternalSubscribed = false;
3693
+ serverOnCloseSubscribed = false;
3694
+ proxyOptions;
3695
+ proxy;
3696
+ pathRewriter;
3697
+ logger;
3698
+ constructor(options){
3699
+ verifyConfig(options);
3700
+ this.proxyOptions = options;
3701
+ this.logger = logger_getLogger(options);
3702
+ Debug("create proxy server");
3703
+ this.proxy = createProxyServer({});
3704
+ this.registerPlugins(this.proxy, this.proxyOptions);
3705
+ this.pathRewriter = createPathRewriter(this.proxyOptions.pathRewrite);
3706
+ this.middleware.upgrade = (req, socket, head)=>{
3707
+ if (!this.wsInternalSubscribed) this.handleUpgrade(req, socket, head);
4590
3708
  };
4591
- exports.proxyEventsPlugin = proxyEventsPlugin;
4592
- },
4593
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/router.js" (__unused_rspack_module, exports, __webpack_require__) {
4594
- exports.getTarget = getTarget;
4595
- const is_plain_object_1 = __webpack_require__("./node_modules/.pnpm/is-plain-object@5.0.0/node_modules/is-plain-object/dist/is-plain-object.js");
4596
- const debug_1 = __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/debug.js");
4597
- const debug = debug_1.Debug.extend('router');
4598
- async function getTarget(req, config) {
4599
- let newTarget;
4600
- const router = config.router;
4601
- if ((0, is_plain_object_1.isPlainObject)(router)) newTarget = getTargetFromProxyTable(req, router);
4602
- else if ('function' == typeof router) newTarget = await router(req);
4603
- return newTarget;
4604
- }
4605
- function getTargetFromProxyTable(req, table) {
4606
- let result;
4607
- const host = req.headers.host;
4608
- const path = req.url;
4609
- const hostAndPath = host + path;
4610
- for (const [key, value] of Object.entries(table))if (containsPath(key)) {
4611
- if (hostAndPath.indexOf(key) > -1) {
4612
- result = value;
4613
- debug('match: "%s" -> "%s"', key, result);
4614
- break;
4615
- }
4616
- } else if (key === host) {
4617
- result = value;
4618
- debug('match: "%s" -> "%s"', host, result);
4619
- break;
3709
+ }
3710
+ middleware = async (req, res, next)=>{
3711
+ if (this.shouldProxy(this.proxyOptions.pathFilter, req)) {
3712
+ let activeProxyOptions;
3713
+ try {
3714
+ activeProxyOptions = await this.prepareProxyRequest(req);
3715
+ if (!activeProxyOptions.target && !activeProxyOptions.forward) throw new Error('Must provide a proper URL as target');
3716
+ } catch (err) {
3717
+ next?.(err);
3718
+ return;
4620
3719
  }
4621
- return result;
4622
- }
4623
- function containsPath(v) {
4624
- return v.indexOf('/') > -1;
4625
- }
4626
- },
4627
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/status-code.js" (__unused_rspack_module, exports) {
4628
- exports.getStatusCode = getStatusCode;
4629
- function getStatusCode(errorCode) {
4630
- let statusCode;
4631
- if (/HPE_INVALID/.test(errorCode)) statusCode = 502;
4632
- else switch(errorCode){
4633
- case 'ECONNRESET':
4634
- case 'ENOTFOUND':
4635
- case 'ECONNREFUSED':
4636
- case 'ETIMEDOUT':
4637
- statusCode = 504;
4638
- break;
4639
- default:
4640
- statusCode = 500;
4641
- break;
3720
+ try {
3721
+ Debug("proxy request to target: %O", activeProxyOptions.target);
3722
+ await this.proxy.web(req, res, activeProxyOptions);
3723
+ } catch (err) {
3724
+ this.proxy.emit('error', err, req, res, activeProxyOptions.target);
3725
+ next?.(err);
3726
+ }
3727
+ } else next?.();
3728
+ const server = req.socket?.server;
3729
+ if (server && !this.serverOnCloseSubscribed) {
3730
+ server.on('close', ()=>{
3731
+ Debug('server close signal received: closing proxy server');
3732
+ this.proxy.close(()=>{
3733
+ Debug('proxy server closed');
3734
+ });
3735
+ });
3736
+ this.serverOnCloseSubscribed = true;
3737
+ }
3738
+ if (true === this.proxyOptions.ws && server) this.catchUpgradeRequest(server);
3739
+ };
3740
+ registerPlugins(proxy, options) {
3741
+ const plugins = getPlugins(options);
3742
+ plugins.forEach((plugin)=>{
3743
+ Debug(`register plugin: "${function_getFunctionName(plugin)}"`);
3744
+ plugin(proxy, options);
3745
+ });
3746
+ }
3747
+ catchUpgradeRequest = (server)=>{
3748
+ if (!this.wsInternalSubscribed) {
3749
+ Debug('subscribing to server upgrade event');
3750
+ server.on('upgrade', this.handleUpgrade);
3751
+ this.wsInternalSubscribed = true;
3752
+ }
3753
+ };
3754
+ handleUpgrade = async (req, socket, head)=>{
3755
+ try {
3756
+ if (this.shouldProxy(this.proxyOptions.pathFilter, req)) {
3757
+ const proxiedReq = req;
3758
+ const activeProxyOptions = await this.prepareProxyRequest(proxiedReq);
3759
+ await this.proxy.ws(proxiedReq, socket, activeProxyOptions, head);
3760
+ Debug('server upgrade event received. Proxying WebSocket');
4642
3761
  }
4643
- return statusCode;
3762
+ } catch (err) {
3763
+ this.proxy.emit('error', err, req, socket);
4644
3764
  }
4645
- },
4646
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/utils/function.js" (__unused_rspack_module, exports) {
4647
- exports.getFunctionName = getFunctionName;
4648
- function getFunctionName(fn) {
4649
- return fn.name || '[anonymous Function]';
4650
- }
4651
- },
4652
- "./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/utils/logger-plugin.js" (__unused_rspack_module, exports) {
4653
- exports.getPort = getPort;
4654
- function getPort(sockets) {
4655
- return Object.keys(sockets || {})?.[0]?.split(':')[1];
3765
+ };
3766
+ shouldProxy = (pathFilter, req)=>{
3767
+ try {
3768
+ return matchPathFilter(pathFilter, req.url, req);
3769
+ } catch (err) {
3770
+ Debug('Error: matchPathFilter() called with request url: ', `"${req.url}"`);
3771
+ this.logger.error(err);
3772
+ return false;
4656
3773
  }
4657
- }
4658
- });
4659
- __webpack_require__("./node_modules/.pnpm/http-proxy-middleware@3.0.5/node_modules/http-proxy-middleware/dist/index.js");
4660
- var dist__esModule = true;
4661
- export { dist__esModule as __esModule };
3774
+ };
3775
+ prepareProxyRequest = async (req)=>{
3776
+ const newProxyOptions = Object.assign({}, this.proxyOptions);
3777
+ await this.applyRouter(req, newProxyOptions);
3778
+ normalizeIPv6LiteralTargets(newProxyOptions);
3779
+ await this.applyPathRewrite(req, this.pathRewriter);
3780
+ return newProxyOptions;
3781
+ };
3782
+ applyRouter = async (req, options)=>{
3783
+ let newTarget;
3784
+ if (options.router) {
3785
+ newTarget = await getTarget(req, options);
3786
+ if (newTarget) {
3787
+ Debug('router new target: "%s"', newTarget);
3788
+ options.target = newTarget;
3789
+ }
3790
+ }
3791
+ };
3792
+ applyPathRewrite = async (req, pathRewriter)=>{
3793
+ if (pathRewriter) {
3794
+ const path = await pathRewriter(req.url, req);
3795
+ if ('string' == typeof path) {
3796
+ Debug('pathRewrite new path: %s', path);
3797
+ req.url = path;
3798
+ } else Debug('pathRewrite: no rewritten path found: %s', req.url);
3799
+ }
3800
+ };
3801
+ }
3802
+ function factory_createProxyMiddleware(options) {
3803
+ const { middleware } = new HttpProxyMiddleware(options);
3804
+ return middleware;
3805
+ }
3806
+ Debug.extend('response-interceptor');
3807
+ export { factory_createProxyMiddleware as createProxyMiddleware };