nitro-nightly 4.0.0-20251010-091516-7cafddba → 4.0.0-20251030-091344-d4418b98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/dist/{_chunks/build2.mjs → _build/build.mjs} +108 -58
  2. package/dist/_build/build2.mjs +556 -0
  3. package/dist/_build/info.mjs +1002 -0
  4. package/dist/_build/prepare.mjs +1511 -0
  5. package/dist/_build/snapshot.mjs +185 -0
  6. package/dist/{_chunks/plugin.mjs → _build/vite.mjs} +295 -296
  7. package/dist/_build/vite2.mjs +149 -0
  8. package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +189 -0
  9. package/dist/_chunks/_deps/@jridgewell/remapping.mjs +137 -0
  10. package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +231 -0
  11. package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +173 -0
  12. package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +170 -0
  13. package/dist/_chunks/_deps/@pi0/vite-plugin-fullstack.mjs +575 -0
  14. package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +89 -0
  15. package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +2376 -0
  16. package/dist/_chunks/{index2.mjs → _deps/@rollup/plugin-inject.mjs} +5 -90
  17. package/dist/_chunks/_deps/@rollup/plugin-json.mjs +37 -0
  18. package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +1386 -0
  19. package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +133 -0
  20. package/dist/_chunks/_deps/@rollup/pluginutils.mjs +346 -0
  21. package/dist/_chunks/_deps/acorn.mjs +6225 -0
  22. package/dist/_chunks/_deps/c12.mjs +510 -0
  23. package/dist/_chunks/_deps/chokidar.mjs +1428 -0
  24. package/dist/_chunks/_deps/citty.mjs +460 -0
  25. package/dist/_chunks/_deps/commondir.mjs +77 -0
  26. package/dist/_chunks/_deps/compatx.mjs +76 -0
  27. package/dist/_chunks/_deps/confbox.mjs +300 -0
  28. package/dist/_chunks/_deps/debug.mjs +885 -0
  29. package/dist/_chunks/_deps/deepmerge.mjs +147 -0
  30. package/dist/_chunks/_deps/depd.mjs +550 -0
  31. package/dist/_chunks/_deps/dot-prop.mjs +282 -0
  32. package/dist/_chunks/_deps/dotenv.mjs +555 -0
  33. package/dist/_chunks/_deps/duplexer.mjs +1 -0
  34. package/dist/_chunks/_deps/ee-first.mjs +104 -0
  35. package/dist/_chunks/_deps/encodeurl.mjs +69 -0
  36. package/dist/_chunks/_deps/escape-html.mjs +87 -0
  37. package/dist/_chunks/_deps/escape-string-regexp.mjs +13 -0
  38. package/dist/_chunks/_deps/estree-walker.mjs +433 -0
  39. package/dist/_chunks/_deps/etag.mjs +147 -0
  40. package/dist/_chunks/_deps/exsolve.mjs +1416 -0
  41. package/dist/_chunks/_deps/fdir.mjs +569 -0
  42. package/dist/_chunks/_deps/fresh.mjs +145 -0
  43. package/dist/_chunks/_deps/function-bind.mjs +106 -0
  44. package/dist/_chunks/{index4.mjs → _deps/giget.mjs} +21 -776
  45. package/dist/_chunks/_deps/gzip-size.mjs +19 -0
  46. package/dist/_chunks/_deps/hasown.mjs +19 -0
  47. package/dist/_chunks/_deps/http-errors.mjs +307 -0
  48. package/dist/_chunks/_deps/httpxy.mjs +580 -0
  49. package/dist/_chunks/_deps/inherits.mjs +57 -0
  50. package/dist/_chunks/_deps/is-core-module.mjs +596 -0
  51. package/dist/_chunks/_deps/is-module.mjs +25 -0
  52. package/dist/_chunks/_deps/is-reference.mjs +31 -0
  53. package/dist/_chunks/_deps/js-tokens.mjs +411 -0
  54. package/dist/_chunks/_deps/klona.mjs +137 -0
  55. package/dist/_chunks/_deps/knitwork.mjs +172 -0
  56. package/dist/_chunks/_deps/local-pkg.mjs +163 -0
  57. package/dist/_chunks/_deps/magic-string.mjs +1296 -0
  58. package/dist/_chunks/_deps/mime-db.mjs +11685 -0
  59. package/dist/_chunks/_deps/mime-types.mjs +287 -0
  60. package/dist/_chunks/_deps/mime.mjs +1172 -0
  61. package/dist/_chunks/_deps/mlly.mjs +2413 -0
  62. package/dist/_chunks/_deps/ms.mjs +172 -0
  63. package/dist/_chunks/_deps/node-fetch-native.mjs +3 -0
  64. package/dist/_chunks/_deps/nypm.mjs +219 -0
  65. package/dist/_chunks/_deps/on-finished.mjs +246 -0
  66. package/dist/_chunks/_deps/parseurl.mjs +168 -0
  67. package/dist/_chunks/_deps/path-parse.mjs +85 -0
  68. package/dist/_chunks/{pathe.M-eThtNZ.mjs → _deps/pathe.mjs} +48 -1
  69. package/dist/_chunks/_deps/perfect-debounce.mjs +88 -0
  70. package/dist/_chunks/_deps/picomatch.mjs +2144 -0
  71. package/dist/_chunks/_deps/pkg-types.mjs +247 -0
  72. package/dist/_chunks/{snapshot.mjs → _deps/pretty-bytes.mjs} +1 -105
  73. package/dist/_chunks/_deps/quansync.mjs +99 -0
  74. package/dist/_chunks/_deps/range-parser.mjs +171 -0
  75. package/dist/_chunks/_deps/rc9.mjs +219 -0
  76. package/dist/_chunks/_deps/readdirp.mjs +245 -0
  77. package/dist/_chunks/_deps/resolve.mjs +1260 -0
  78. package/dist/_chunks/_deps/rou3.mjs +326 -0
  79. package/dist/_chunks/_deps/send.mjs +1022 -0
  80. package/dist/_chunks/_deps/serve-static.mjs +228 -0
  81. package/dist/_chunks/_deps/setprototypeof.mjs +26 -0
  82. package/dist/_chunks/_deps/statuses.mjs +457 -0
  83. package/dist/_chunks/_deps/std-env.mjs +3 -0
  84. package/dist/_chunks/_deps/strip-literal.mjs +67 -0
  85. package/dist/_chunks/_deps/supports-color.mjs +44 -0
  86. package/dist/_chunks/_deps/tinyexec.mjs +552 -0
  87. package/dist/_chunks/_deps/tinyglobby.mjs +293 -0
  88. package/dist/_chunks/_deps/toidentifier.mjs +41 -0
  89. package/dist/_chunks/_deps/ultrahtml.mjs +3 -0
  90. package/dist/_chunks/_deps/unimport.mjs +2267 -0
  91. package/dist/_chunks/_deps/unplugin-utils.mjs +65 -0
  92. package/dist/_chunks/_deps/unplugin.mjs +1294 -0
  93. package/dist/_chunks/_deps/untyped.mjs +375 -0
  94. package/dist/_chunks/{info.mjs → _deps/unwasm.mjs} +8 -4206
  95. package/dist/_chunks/_deps/webpack-virtual-modules.mjs +360 -0
  96. package/dist/_chunks/_presets/_all.mjs +59 -0
  97. package/dist/_chunks/_presets/_nitro.mjs +74 -0
  98. package/dist/_chunks/_presets/_resolve.mjs +64 -0
  99. package/dist/_chunks/_presets/_static.mjs +69 -0
  100. package/dist/_chunks/_presets/_types.mjs +3 -0
  101. package/dist/_chunks/_presets/_utils.mjs +31 -0
  102. package/dist/_chunks/_presets/alwaysdata.mjs +17 -0
  103. package/dist/_chunks/_presets/aws-amplify.mjs +111 -0
  104. package/dist/_chunks/_presets/aws-lambda.mjs +23 -0
  105. package/dist/_chunks/_presets/azure.mjs +162 -0
  106. package/dist/_chunks/_presets/bun.mjs +19 -0
  107. package/dist/_chunks/_presets/cleavr.mjs +15 -0
  108. package/dist/_chunks/_presets/cloudflare.mjs +608 -0
  109. package/dist/_chunks/_presets/deno.mjs +196 -0
  110. package/dist/_chunks/_presets/digitalocean.mjs +14 -0
  111. package/dist/_chunks/_presets/firebase.mjs +47 -0
  112. package/dist/_chunks/_presets/flightcontrol.mjs +14 -0
  113. package/dist/_chunks/_presets/genezio.mjs +13 -0
  114. package/dist/_chunks/_presets/heroku.mjs +14 -0
  115. package/dist/_chunks/_presets/iis.mjs +194 -0
  116. package/dist/_chunks/_presets/index.mjs +62 -0
  117. package/dist/_chunks/_presets/koyeb.mjs +14 -0
  118. package/dist/_chunks/_presets/netlify.mjs +241 -0
  119. package/dist/_chunks/_presets/node.mjs +54 -0
  120. package/dist/_chunks/_presets/platform.mjs +14 -0
  121. package/dist/_chunks/_presets/render.mjs +14 -0
  122. package/dist/_chunks/_presets/standard.mjs +23 -0
  123. package/dist/_chunks/_presets/stormkit.mjs +18 -0
  124. package/dist/_chunks/_presets/vercel.mjs +375 -0
  125. package/dist/_chunks/_presets/winterjs.mjs +22 -0
  126. package/dist/_chunks/_presets/zeabur.mjs +69 -0
  127. package/dist/_chunks/_presets/zerops.mjs +27 -0
  128. package/dist/_chunks/app.mjs +9 -19206
  129. package/dist/_chunks/{index3.mjs → builder.mjs} +560 -970
  130. package/dist/_chunks/server.mjs +6 -4
  131. package/dist/{cli → _cli}/build.mjs +3 -8
  132. package/dist/{cli → _cli}/dev.mjs +38 -12
  133. package/dist/{cli/index2.mjs → _cli/index.mjs} +1 -2
  134. package/dist/{cli → _cli}/list.mjs +3 -4
  135. package/dist/{cli → _cli}/prepare.mjs +3 -4
  136. package/dist/{cli → _cli}/run.mjs +3 -4
  137. package/dist/{index.d.mts → builder.d.mts} +11 -11
  138. package/dist/builder.mjs +117 -0
  139. package/dist/cli/index.mjs +7 -464
  140. package/dist/node_modules/@speed-highlight/core/dist/index.js +1 -1
  141. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +1 -1
  142. package/dist/node_modules/@speed-highlight/core/package.json +7 -3
  143. package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
  144. package/dist/node_modules/cookie-es/package.json +37 -0
  145. package/dist/node_modules/hookable/dist/index.mjs +243 -266
  146. package/dist/node_modules/hookable/package.json +29 -26
  147. package/dist/node_modules/rendu/dist/index.mjs +380 -0
  148. package/dist/node_modules/rendu/package.json +47 -0
  149. package/dist/presets/_nitro/runtime/nitro-dev.mjs +4 -7
  150. package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +5 -4
  151. package/dist/presets/azure/runtime/azure-swa.mjs +1 -1
  152. package/dist/presets/cloudflare/runtime/_module-handler.mjs +7 -6
  153. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -5
  154. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +7 -10
  155. package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +21 -0
  156. package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
  157. package/dist/presets/node/runtime/node-server.mjs +1 -1
  158. package/dist/runtime/index.d.mts +1 -1
  159. package/dist/runtime/index.mjs +1 -1
  160. package/dist/runtime/internal/app.d.mts +3 -1
  161. package/dist/runtime/internal/app.mjs +90 -64
  162. package/dist/runtime/internal/error/prod.d.mts +3 -2
  163. package/dist/runtime/internal/error/prod.mjs +9 -13
  164. package/dist/runtime/internal/renderer.mjs +4 -4
  165. package/dist/runtime/internal/routes/dev-tasks.d.mts +30 -2
  166. package/dist/runtime/internal/shutdown.d.mts +1 -2
  167. package/dist/runtime/internal/shutdown.mjs +3 -2
  168. package/dist/runtime/internal/task.mjs +1 -2
  169. package/dist/types/index.d.mts +1603 -10
  170. package/dist/vite.d.mts +5 -0
  171. package/dist/vite.mjs +94 -30
  172. package/lib/index.mjs +1 -0
  173. package/lib/indexd.mts +1 -0
  174. package/lib/runtime/meta.mjs +35 -0
  175. package/package.json +40 -41
  176. package/dist/_chunks/build.mjs +0 -84
  177. package/dist/_chunks/build3.mjs +0 -6452
  178. package/dist/_chunks/detect-acorn.mjs +0 -503
  179. package/dist/_chunks/index.mjs +0 -22242
  180. package/dist/_chunks/json5.mjs +0 -68
  181. package/dist/_chunks/jsonc.mjs +0 -51
  182. package/dist/_chunks/toml.mjs +0 -259
  183. package/dist/_chunks/yaml.mjs +0 -86
  184. package/dist/index.mjs +0 -55
  185. package/dist/node_modules/klona/dist/index.mjs +0 -81
  186. package/dist/node_modules/klona/full/index.mjs +0 -53
  187. package/dist/node_modules/klona/package.json +0 -74
  188. package/dist/node_modules/std-env/dist/index.mjs +0 -1
  189. package/dist/node_modules/std-env/package.json +0 -46
  190. package/dist/presets.mjs +0 -2460
  191. package/dist/runtime/internal/debug.d.mts +0 -2
  192. package/dist/runtime/internal/debug.mjs +0 -5
  193. package/lib/runtime-meta.mjs +0 -38
  194. /package/dist/{cli → _cli}/common.mjs +0 -0
  195. /package/lib/{runtime-meta.d.mts → runtime/meta.d.mts} +0 -0
@@ -0,0 +1,580 @@
1
+ import http from 'node:http';
2
+ import https from 'node:https';
3
+ import { EventEmitter } from 'node:events';
4
+
5
+ const upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
6
+ const isSSL = /^https|wss/;
7
+ function setupOutgoing(outgoing, options, req, forward) {
8
+ outgoing.port = options[forward || "target"].port || (isSSL.test(options[forward || "target"].protocol) ? 443 : 80);
9
+ for (const e of [
10
+ "host",
11
+ "hostname",
12
+ "socketPath",
13
+ "pfx",
14
+ "key",
15
+ "passphrase",
16
+ "cert",
17
+ "ca",
18
+ "ciphers",
19
+ "secureProtocol"
20
+ ]) {
21
+ outgoing[e] = options[forward || "target"][e];
22
+ }
23
+ outgoing.method = options.method || req.method;
24
+ outgoing.headers = { ...req.headers };
25
+ if (options.headers) {
26
+ outgoing.headers = { ...outgoing.headers, ...options.headers };
27
+ }
28
+ if (options.auth) {
29
+ outgoing.auth = options.auth;
30
+ }
31
+ if (options.ca) {
32
+ outgoing.ca = options.ca;
33
+ }
34
+ if (isSSL.test(options[forward || "target"].protocol)) {
35
+ outgoing.rejectUnauthorized = options.secure === undefined ? true : options.secure;
36
+ }
37
+ outgoing.agent = options.agent || false;
38
+ outgoing.localAddress = options.localAddress;
39
+ if (!outgoing.agent) {
40
+ outgoing.headers = outgoing.headers || {};
41
+ if (typeof outgoing.headers.connection !== "string" || !upgradeHeader.test(outgoing.headers.connection)) {
42
+ outgoing.headers.connection = "close";
43
+ }
44
+ }
45
+ const target = options[forward || "target"];
46
+ const targetPath = target && options.prependPath !== false ? target.pathname || target.path || "" : "";
47
+ const parsed = new URL(req.url, "http://localhost");
48
+ let outgoingPath = options.toProxy ? req.url : parsed.pathname + parsed.search || "";
49
+ outgoingPath = options.ignorePath ? "" : outgoingPath;
50
+ outgoing.path = joinURL(targetPath, outgoingPath);
51
+ if (options.changeOrigin) {
52
+ outgoing.headers.host = requiresPort(outgoing.port, options[forward || "target"].protocol) && !hasPort(outgoing.host) ? outgoing.host + ":" + outgoing.port : outgoing.host;
53
+ }
54
+ return outgoing;
55
+ }
56
+ function joinURL(base, path) {
57
+ if (!base || base === "/") {
58
+ return path || "/";
59
+ }
60
+ if (!path || path === "/") {
61
+ return base || "/";
62
+ }
63
+ const baseHasTrailing = base[base.length - 1] === "/";
64
+ const pathHasLeading = path[0] === "/";
65
+ if (baseHasTrailing && pathHasLeading) {
66
+ return base + path.slice(1);
67
+ }
68
+ if (!baseHasTrailing && !pathHasLeading) {
69
+ return base + "/" + path;
70
+ }
71
+ return base + path;
72
+ }
73
+ function setupSocket(socket) {
74
+ socket.setTimeout(0);
75
+ socket.setNoDelay(true);
76
+ socket.setKeepAlive(true, 0);
77
+ return socket;
78
+ }
79
+ function getPort(req) {
80
+ const res = req.headers.host ? req.headers.host.match(/:(\d+)/) : "";
81
+ if (res) {
82
+ return res[1];
83
+ }
84
+ return hasEncryptedConnection(req) ? "443" : "80";
85
+ }
86
+ function hasEncryptedConnection(req) {
87
+ return Boolean(req.connection.encrypted || req.connection.pair);
88
+ }
89
+ function rewriteCookieProperty(header, config, property) {
90
+ if (Array.isArray(header)) {
91
+ return header.map(function(headerElement) {
92
+ return rewriteCookieProperty(headerElement, config, property);
93
+ });
94
+ }
95
+ return header.replace(
96
+ new RegExp(String.raw`(;\s*` + property + "=)([^;]+)", "i"),
97
+ function(match, prefix, previousValue) {
98
+ let newValue;
99
+ if (previousValue in config) {
100
+ newValue = config[previousValue];
101
+ } else if ("*" in config) {
102
+ newValue = config["*"];
103
+ } else {
104
+ return match;
105
+ }
106
+ return newValue ? prefix + newValue : "";
107
+ }
108
+ );
109
+ }
110
+ function hasPort(host) {
111
+ return !!~host.indexOf(":");
112
+ }
113
+ function requiresPort(_port, _protocol) {
114
+ const protocol = _protocol.split(":")[0];
115
+ const port = +_port;
116
+ if (!port) return false;
117
+ switch (protocol) {
118
+ case "http":
119
+ case "ws": {
120
+ return port !== 80;
121
+ }
122
+ case "https":
123
+ case "wss": {
124
+ return port !== 443;
125
+ }
126
+ case "ftp": {
127
+ return port !== 21;
128
+ }
129
+ case "gopher": {
130
+ return port !== 70;
131
+ }
132
+ case "file": {
133
+ return false;
134
+ }
135
+ }
136
+ return port !== 0;
137
+ }
138
+
139
+ function defineProxyMiddleware(m) {
140
+ return m;
141
+ }
142
+ function defineProxyOutgoingMiddleware(m) {
143
+ return m;
144
+ }
145
+
146
+ const redirectRegex = /^201|30([1278])$/;
147
+ const removeChunked = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
148
+ if (req.httpVersion === "1.0") {
149
+ delete proxyRes.headers["transfer-encoding"];
150
+ }
151
+ });
152
+ const setConnection = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
153
+ if (req.httpVersion === "1.0") {
154
+ proxyRes.headers.connection = req.headers.connection || "close";
155
+ } else if (req.httpVersion !== "2.0" && !proxyRes.headers.connection) {
156
+ proxyRes.headers.connection = req.headers.connection || "keep-alive";
157
+ }
158
+ });
159
+ const setRedirectHostRewrite = defineProxyOutgoingMiddleware(
160
+ (req, res, proxyRes, options) => {
161
+ if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite) && proxyRes.headers.location && redirectRegex.test(String(proxyRes.statusCode))) {
162
+ const target = new URL(options.target);
163
+ const u = new URL(proxyRes.headers.location);
164
+ if (target.host !== u.host) {
165
+ return;
166
+ }
167
+ if (options.hostRewrite) {
168
+ u.host = options.hostRewrite;
169
+ } else if (options.autoRewrite) {
170
+ u.host = req.headers.host;
171
+ }
172
+ if (options.protocolRewrite) {
173
+ u.protocol = options.protocolRewrite;
174
+ }
175
+ proxyRes.headers.location = u.toString();
176
+ }
177
+ }
178
+ );
179
+ const writeHeaders = defineProxyOutgoingMiddleware(
180
+ (req, res, proxyRes, options) => {
181
+ let rewriteCookieDomainConfig = options.cookieDomainRewrite;
182
+ let rewriteCookiePathConfig = options.cookiePathRewrite;
183
+ const preserveHeaderKeyCase = options.preserveHeaderKeyCase;
184
+ let rawHeaderKeyMap;
185
+ const setHeader = function(key, header) {
186
+ if (header === undefined) {
187
+ return;
188
+ }
189
+ if (rewriteCookieDomainConfig && key.toLowerCase() === "set-cookie") {
190
+ header = rewriteCookieProperty(
191
+ header,
192
+ rewriteCookieDomainConfig,
193
+ "domain"
194
+ );
195
+ }
196
+ if (rewriteCookiePathConfig && key.toLowerCase() === "set-cookie") {
197
+ header = rewriteCookieProperty(header, rewriteCookiePathConfig, "path");
198
+ }
199
+ res.setHeader(String(key).trim(), header);
200
+ };
201
+ if (typeof rewriteCookieDomainConfig === "string") {
202
+ rewriteCookieDomainConfig = { "*": rewriteCookieDomainConfig };
203
+ }
204
+ if (typeof rewriteCookiePathConfig === "string") {
205
+ rewriteCookiePathConfig = { "*": rewriteCookiePathConfig };
206
+ }
207
+ if (preserveHeaderKeyCase && proxyRes.rawHeaders !== undefined) {
208
+ rawHeaderKeyMap = {};
209
+ for (let i = 0; i < proxyRes.rawHeaders.length; i += 2) {
210
+ const key = proxyRes.rawHeaders[i];
211
+ rawHeaderKeyMap[key.toLowerCase()] = key;
212
+ }
213
+ }
214
+ for (let key of Object.keys(proxyRes.headers)) {
215
+ const header = proxyRes.headers[key];
216
+ if (preserveHeaderKeyCase && rawHeaderKeyMap) {
217
+ key = rawHeaderKeyMap[key] || key;
218
+ }
219
+ setHeader(key, header);
220
+ }
221
+ }
222
+ );
223
+ const writeStatusCode = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
224
+ if (proxyRes.statusMessage) {
225
+ res.statusCode = proxyRes.statusCode;
226
+ res.statusMessage = proxyRes.statusMessage;
227
+ } else {
228
+ res.statusCode = proxyRes.statusCode;
229
+ }
230
+ });
231
+ const webOutgoingMiddleware = [
232
+ removeChunked,
233
+ setConnection,
234
+ setRedirectHostRewrite,
235
+ writeHeaders,
236
+ writeStatusCode
237
+ ];
238
+
239
+ const nativeAgents = { http: http, https: https };
240
+ const deleteLength = defineProxyMiddleware((req) => {
241
+ if ((req.method === "DELETE" || req.method === "OPTIONS") && !req.headers["content-length"]) {
242
+ req.headers["content-length"] = "0";
243
+ delete req.headers["transfer-encoding"];
244
+ }
245
+ });
246
+ const timeout = defineProxyMiddleware((req, res, options) => {
247
+ if (options.timeout) {
248
+ req.socket.setTimeout(options.timeout);
249
+ }
250
+ });
251
+ const XHeaders$1 = defineProxyMiddleware((req, res, options) => {
252
+ if (!options.xfwd) {
253
+ return;
254
+ }
255
+ const encrypted = req.isSpdy || hasEncryptedConnection(req);
256
+ const values = {
257
+ for: req.connection.remoteAddress || req.socket.remoteAddress,
258
+ port: getPort(req),
259
+ proto: encrypted ? "https" : "http"
260
+ };
261
+ for (const header of ["for", "port", "proto"]) {
262
+ req.headers["x-forwarded-" + header] = (req.headers["x-forwarded-" + header] || "") + (req.headers["x-forwarded-" + header] ? "," : "") + values[header];
263
+ }
264
+ req.headers["x-forwarded-host"] = req.headers["x-forwarded-host"] || req.headers.host || "";
265
+ });
266
+ const stream$1 = defineProxyMiddleware(
267
+ (req, res, options, server, head, callback) => {
268
+ server.emit("start", req, res, options.target || options.forward);
269
+ const agents = nativeAgents;
270
+ const http = agents.http;
271
+ const https = agents.https;
272
+ if (options.forward) {
273
+ const forwardReq = (options.forward.protocol === "https:" ? https : http).request(setupOutgoing(options.ssl || {}, options, req, "forward"));
274
+ const forwardError = createErrorHandler(forwardReq, options.forward);
275
+ req.on("error", forwardError);
276
+ forwardReq.on("error", forwardError);
277
+ (options.buffer || req).pipe(forwardReq);
278
+ if (!options.target) {
279
+ res.end();
280
+ return;
281
+ }
282
+ }
283
+ const proxyReq = (options.target.protocol === "https:" ? https : http).request(setupOutgoing(options.ssl || {}, options, req));
284
+ proxyReq.on("socket", (socket) => {
285
+ if (server && !proxyReq.getHeader("expect")) {
286
+ server.emit("proxyReq", proxyReq, req, res, options);
287
+ }
288
+ });
289
+ if (options.proxyTimeout) {
290
+ proxyReq.setTimeout(options.proxyTimeout, function() {
291
+ proxyReq.abort();
292
+ });
293
+ }
294
+ req.on("aborted", function() {
295
+ proxyReq.abort();
296
+ });
297
+ const proxyError = createErrorHandler(proxyReq, options.target);
298
+ req.on("error", proxyError);
299
+ proxyReq.on("error", proxyError);
300
+ function createErrorHandler(proxyReq2, url) {
301
+ return function proxyError2(err) {
302
+ if (req.socket.destroyed && err.code === "ECONNRESET") {
303
+ server.emit("econnreset", err, req, res, url);
304
+ return proxyReq2.abort();
305
+ }
306
+ if (callback) {
307
+ callback(err, req, res, url);
308
+ } else {
309
+ server.emit("error", err, req, res, url);
310
+ }
311
+ };
312
+ }
313
+ (options.buffer || req).pipe(proxyReq);
314
+ proxyReq.on("response", function(proxyRes) {
315
+ if (server) {
316
+ server.emit("proxyRes", proxyRes, req, res);
317
+ }
318
+ if (!res.headersSent && !options.selfHandleResponse) {
319
+ for (const pass of webOutgoingMiddleware) {
320
+ if (pass(req, res, proxyRes, options)) {
321
+ break;
322
+ }
323
+ }
324
+ }
325
+ if (res.finished) {
326
+ if (server) {
327
+ server.emit("end", req, res, proxyRes);
328
+ }
329
+ } else {
330
+ res.on("close", function() {
331
+ proxyRes.destroy();
332
+ });
333
+ proxyRes.on("end", function() {
334
+ if (server) {
335
+ server.emit("end", req, res, proxyRes);
336
+ }
337
+ });
338
+ if (!options.selfHandleResponse) {
339
+ proxyRes.pipe(res);
340
+ }
341
+ }
342
+ });
343
+ }
344
+ );
345
+ const webIncomingMiddleware = [
346
+ deleteLength,
347
+ timeout,
348
+ XHeaders$1,
349
+ stream$1
350
+ ];
351
+
352
+ const checkMethodAndHeader = defineProxyMiddleware((req, socket) => {
353
+ if (req.method !== "GET" || !req.headers.upgrade) {
354
+ socket.destroy();
355
+ return true;
356
+ }
357
+ if (req.headers.upgrade.toLowerCase() !== "websocket") {
358
+ socket.destroy();
359
+ return true;
360
+ }
361
+ });
362
+ const XHeaders = defineProxyMiddleware((req, socket, options) => {
363
+ if (!options.xfwd) {
364
+ return;
365
+ }
366
+ const values = {
367
+ for: req.connection.remoteAddress || req.socket.remoteAddress,
368
+ port: getPort(req),
369
+ proto: hasEncryptedConnection(req) ? "wss" : "ws"
370
+ };
371
+ for (const header of ["for", "port", "proto"]) {
372
+ req.headers["x-forwarded-" + header] = (req.headers["x-forwarded-" + header] || "") + (req.headers["x-forwarded-" + header] ? "," : "") + values[header];
373
+ }
374
+ });
375
+ const stream = defineProxyMiddleware(
376
+ (req, socket, options, server, head, callback) => {
377
+ const createHttpHeader = function(line, headers) {
378
+ return Object.keys(headers).reduce(
379
+ function(head2, key) {
380
+ const value = headers[key];
381
+ if (!Array.isArray(value)) {
382
+ head2.push(key + ": " + value);
383
+ return head2;
384
+ }
385
+ for (const element of value) {
386
+ head2.push(key + ": " + element);
387
+ }
388
+ return head2;
389
+ },
390
+ [line]
391
+ ).join("\r\n") + "\r\n\r\n";
392
+ };
393
+ setupSocket(socket);
394
+ if (head && head.length > 0) {
395
+ socket.unshift(head);
396
+ }
397
+ const proxyReq = (isSSL.test(options.target.protocol) ? https : http).request(setupOutgoing(options.ssl || {}, options, req));
398
+ if (server) {
399
+ server.emit("proxyReqWs", proxyReq, req, socket, options, head);
400
+ }
401
+ proxyReq.on("error", onOutgoingError);
402
+ proxyReq.on("response", function(res) {
403
+ if (!res.upgrade) {
404
+ socket.write(
405
+ createHttpHeader(
406
+ "HTTP/" + res.httpVersion + " " + res.statusCode + " " + res.statusMessage,
407
+ res.headers
408
+ )
409
+ );
410
+ res.pipe(socket);
411
+ }
412
+ });
413
+ proxyReq.on("upgrade", function(proxyRes, proxySocket, proxyHead) {
414
+ proxySocket.on("error", onOutgoingError);
415
+ proxySocket.on("end", function() {
416
+ server.emit("close", proxyRes, proxySocket, proxyHead);
417
+ });
418
+ socket.on("error", function() {
419
+ proxySocket.end();
420
+ });
421
+ setupSocket(proxySocket);
422
+ if (proxyHead && proxyHead.length > 0) {
423
+ proxySocket.unshift(proxyHead);
424
+ }
425
+ socket.write(
426
+ createHttpHeader("HTTP/1.1 101 Switching Protocols", proxyRes.headers)
427
+ );
428
+ proxySocket.pipe(socket).pipe(proxySocket);
429
+ server.emit("open", proxySocket);
430
+ server.emit("proxySocket", proxySocket);
431
+ });
432
+ proxyReq.end();
433
+ function onOutgoingError(err) {
434
+ if (callback) {
435
+ callback(err, req, socket);
436
+ } else {
437
+ server.emit("error", err, req, socket);
438
+ }
439
+ socket.end();
440
+ }
441
+ }
442
+ );
443
+ const websocketIncomingMiddleware = [
444
+ checkMethodAndHeader,
445
+ XHeaders,
446
+ stream
447
+ ];
448
+
449
+ class ProxyServer extends EventEmitter {
450
+ _server;
451
+ _webPasses = [...webIncomingMiddleware];
452
+ _wsPasses = [...websocketIncomingMiddleware];
453
+ options;
454
+ web;
455
+ ws;
456
+ /**
457
+ * Creates the proxy server with specified options.
458
+ * @param options - Config object passed to the proxy
459
+ */
460
+ constructor(options = {}) {
461
+ super();
462
+ this.options = options || {};
463
+ this.options.prependPath = options.prependPath !== false;
464
+ this.web = _createProxyFn("web", this);
465
+ this.ws = _createProxyFn("ws", this);
466
+ }
467
+ /**
468
+ * A function that wraps the object in a webserver, for your convenience
469
+ * @param port - Port to listen on
470
+ * @param hostname - The hostname to listen on
471
+ */
472
+ listen(port, hostname) {
473
+ const closure = (req, res) => {
474
+ this.web(req, res);
475
+ };
476
+ this._server = this.options.ssl ? https.createServer(this.options.ssl, closure) : http.createServer(closure);
477
+ if (this.options.ws) {
478
+ this._server.on("upgrade", (req, socket, head) => {
479
+ this._ws(req, socket, head);
480
+ });
481
+ }
482
+ this._server.listen(port, hostname);
483
+ return this;
484
+ }
485
+ /**
486
+ * A function that closes the inner webserver and stops listening on given port
487
+ */
488
+ close(callback) {
489
+ if (this._server) {
490
+ this._server.close((...args) => {
491
+ this._server = undefined;
492
+ if (callback) {
493
+ Reflect.apply(callback, undefined, args);
494
+ }
495
+ });
496
+ }
497
+ }
498
+ before(type, passName, pass) {
499
+ if (type !== "ws" && type !== "web") {
500
+ throw new Error("type must be `web` or `ws`");
501
+ }
502
+ const passes = type === "ws" ? this._wsPasses : this._webPasses;
503
+ let i = false;
504
+ for (const [idx, v] of passes.entries()) {
505
+ if (v.name === passName) {
506
+ i = idx;
507
+ }
508
+ }
509
+ if (i === false) {
510
+ throw new Error("No such pass");
511
+ }
512
+ passes.splice(i, 0, pass);
513
+ }
514
+ after(type, passName, pass) {
515
+ if (type !== "ws" && type !== "web") {
516
+ throw new Error("type must be `web` or `ws`");
517
+ }
518
+ const passes = type === "ws" ? this._wsPasses : this._webPasses;
519
+ let i = false;
520
+ for (const [idx, v] of passes.entries()) {
521
+ if (v.name === passName) {
522
+ i = idx;
523
+ }
524
+ }
525
+ if (i === false) {
526
+ throw new Error("No such pass");
527
+ }
528
+ passes.splice(i++, 0, pass);
529
+ }
530
+ }
531
+ function createProxyServer(options = {}) {
532
+ return new ProxyServer(options);
533
+ }
534
+ function _createProxyFn(type, server) {
535
+ return function(req, res, opts, head) {
536
+ const requestOptions = { ...opts, ...server.options };
537
+ for (const key of ["target", "forward"]) {
538
+ if (typeof requestOptions[key] === "string") {
539
+ requestOptions[key] = new URL(requestOptions[key]);
540
+ }
541
+ }
542
+ if (!requestOptions.target && !requestOptions.forward) {
543
+ return this.emit(
544
+ "error",
545
+ new Error("Must provide a proper URL as target")
546
+ );
547
+ }
548
+ let _resolve;
549
+ let _reject;
550
+ const callbackPromise = new Promise((resolve, reject) => {
551
+ _resolve = resolve;
552
+ _reject = reject;
553
+ });
554
+ res.on("close", () => {
555
+ _resolve();
556
+ });
557
+ res.on("error", (error) => {
558
+ _reject(error);
559
+ });
560
+ for (const pass of type === "ws" ? server._wsPasses : server._webPasses) {
561
+ const stop = pass(
562
+ req,
563
+ res,
564
+ requestOptions,
565
+ server,
566
+ head,
567
+ (error) => {
568
+ _reject(error);
569
+ }
570
+ );
571
+ if (stop) {
572
+ _resolve();
573
+ break;
574
+ }
575
+ }
576
+ return callbackPromise;
577
+ };
578
+ }
579
+
580
+ export { createProxyServer as c };
@@ -0,0 +1,57 @@
1
+ var inherits = {exports: {}};
2
+
3
+ var inherits_browser = {exports: {}};
4
+
5
+ var hasRequiredInherits_browser;
6
+
7
+ function requireInherits_browser () {
8
+ if (hasRequiredInherits_browser) return inherits_browser.exports;
9
+ hasRequiredInherits_browser = 1;
10
+ if (typeof Object.create === 'function') {
11
+ // implementation from standard node.js 'util' module
12
+ inherits_browser.exports = function inherits(ctor, superCtor) {
13
+ if (superCtor) {
14
+ ctor.super_ = superCtor;
15
+ ctor.prototype = Object.create(superCtor.prototype, {
16
+ constructor: {
17
+ value: ctor,
18
+ enumerable: false,
19
+ writable: true,
20
+ configurable: true
21
+ }
22
+ });
23
+ }
24
+ };
25
+ } else {
26
+ // old school shim for old browsers
27
+ inherits_browser.exports = function inherits(ctor, superCtor) {
28
+ if (superCtor) {
29
+ ctor.super_ = superCtor;
30
+ var TempCtor = function () {};
31
+ TempCtor.prototype = superCtor.prototype;
32
+ ctor.prototype = new TempCtor();
33
+ ctor.prototype.constructor = ctor;
34
+ }
35
+ };
36
+ }
37
+ return inherits_browser.exports;
38
+ }
39
+
40
+ var hasRequiredInherits;
41
+
42
+ function requireInherits () {
43
+ if (hasRequiredInherits) return inherits.exports;
44
+ hasRequiredInherits = 1;
45
+ try {
46
+ var util = require('util');
47
+ /* istanbul ignore next */
48
+ if (typeof util.inherits !== 'function') throw '';
49
+ inherits.exports = util.inherits;
50
+ } catch (e) {
51
+ /* istanbul ignore next */
52
+ inherits.exports = requireInherits_browser();
53
+ }
54
+ return inherits.exports;
55
+ }
56
+
57
+ export { requireInherits as r };