nitro-nightly 4.0.0-20251030-091344-d4418b98 → 4.0.0-20251030-122334-09c1a7a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_build/common.mjs +763 -0
- package/dist/_build/rolldown.mjs +216 -0
- package/dist/_build/rollup.mjs +359 -0
- package/dist/_build/vite.build.mjs +67 -0
- package/dist/_build/vite.plugin.mjs +762 -0
- package/dist/_chunks/B-7HiF0V.mjs +1303 -0
- package/dist/_chunks/B3asVbT4.mjs +151 -0
- package/dist/_chunks/B5ooyfLk.mjs +372 -0
- package/dist/_chunks/DXMHy5ca.mjs +43 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +675 -0
- package/dist/_libs/acorn.mjs +5034 -0
- package/dist/_libs/c12.mjs +2798 -0
- package/dist/_libs/chokidar.mjs +1560 -0
- package/dist/_libs/citty.mjs +333 -0
- package/dist/_libs/commondir.mjs +22 -0
- package/dist/_libs/compatx.mjs +46 -0
- package/dist/_libs/confbox.mjs +2920 -0
- package/dist/_libs/debug.mjs +848 -0
- package/dist/_libs/deepmerge.mjs +86 -0
- package/dist/_libs/depd.mjs +314 -0
- package/dist/_libs/dot-prop.mjs +138 -0
- package/dist/_libs/duplexer.mjs +71 -0
- package/dist/_libs/ee-first.mjs +68 -0
- package/dist/_libs/encodeurl.mjs +49 -0
- package/dist/_libs/escape-html.mjs +58 -0
- package/dist/_libs/escape-string-regexp.mjs +8 -0
- package/dist/_libs/estree-walker.mjs +330 -0
- package/dist/_libs/etag.mjs +75 -0
- package/dist/{_chunks/_deps → _libs}/fdir.mjs +49 -104
- package/dist/_libs/fresh.mjs +85 -0
- package/dist/_libs/function-bind.mjs +63 -0
- package/dist/_libs/gen-mapping.mjs +612 -0
- package/dist/_libs/giget.mjs +19076 -0
- package/dist/_libs/gzip-size.mjs +21 -0
- package/dist/_libs/hasown.mjs +14 -0
- package/dist/_libs/http-errors.mjs +436 -0
- package/dist/_libs/httpxy.mjs +410 -0
- package/dist/_libs/is-core-module.mjs +220 -0
- package/dist/_libs/is-module.mjs +13 -0
- package/dist/_libs/is-reference.mjs +32 -0
- package/dist/{_chunks/_deps → _libs}/js-tokens.mjs +83 -112
- package/dist/_libs/klona.mjs +90 -0
- package/dist/_libs/knitwork.mjs +124 -0
- package/dist/_libs/local-pkg.mjs +1686 -0
- package/dist/{_chunks/_deps → _libs}/magic-string.mjs +272 -629
- package/dist/_libs/mime-db.mjs +7642 -0
- package/dist/_libs/mime-types.mjs +162 -0
- package/dist/_libs/mime.mjs +1391 -0
- package/dist/_libs/node-fetch-native.mjs +173 -0
- package/dist/_libs/on-finished.mjs +170 -0
- package/dist/_libs/parseurl.mjs +103 -0
- package/dist/_libs/path-parse.mjs +47 -0
- package/dist/_libs/pathe.mjs +41 -0
- package/dist/_libs/picomatch.mjs +1673 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/plugin-commonjs.mjs +1489 -0
- package/dist/_libs/plugin-inject.mjs +135 -0
- package/dist/_libs/plugin-json.mjs +36 -0
- package/dist/_libs/plugin-node-resolve.mjs +1553 -0
- package/dist/_libs/plugin-replace.mjs +104 -0
- package/dist/_libs/pretty-bytes.mjs +116 -0
- package/dist/_libs/range-parser.mjs +102 -0
- package/dist/_libs/remapping.mjs +117 -0
- package/dist/{_chunks/_deps → _libs}/rou3.mjs +7 -22
- package/dist/_libs/send.mjs +857 -0
- package/dist/_libs/serve-static.mjs +124 -0
- package/dist/_libs/std-env.mjs +158 -0
- package/dist/_libs/strip-literal.mjs +51 -0
- package/dist/{_chunks/_deps → _libs}/tinyglobby.mjs +32 -33
- package/dist/_libs/ultrahtml.mjs +138 -0
- package/dist/_libs/unimport.mjs +3520 -0
- package/dist/_libs/untyped.mjs +271 -0
- package/dist/_libs/unwasm.mjs +5825 -0
- package/dist/{_chunks/_deps/@pi0 → _libs}/vite-plugin-fullstack.mjs +28 -42
- package/dist/_presets.mjs +1723 -0
- package/dist/builder.d.mts +37 -35
- package/dist/builder.mjs +45 -117
- package/dist/cli/_chunks/build.mjs +43 -0
- package/dist/cli/_chunks/common.mjs +15 -0
- package/dist/cli/_chunks/detect-acorn.mjs +12 -0
- package/dist/cli/_chunks/dev.mjs +79 -0
- package/dist/cli/_chunks/dist.mjs +3 -0
- package/dist/cli/_chunks/dist2.mjs +4 -0
- package/dist/cli/_chunks/esm.mjs +3 -0
- package/dist/cli/_chunks/json5.mjs +4 -0
- package/dist/cli/_chunks/jsonc.mjs +4 -0
- package/dist/cli/_chunks/list.mjs +27 -0
- package/dist/cli/_chunks/multipart-parser.mjs +6 -0
- package/dist/cli/_chunks/prepare.mjs +19 -0
- package/dist/cli/_chunks/run.mjs +55 -0
- package/dist/cli/_chunks/task.mjs +16 -0
- package/dist/cli/_chunks/toml.mjs +4 -0
- package/dist/cli/_chunks/yaml.mjs +4 -0
- package/dist/cli/index.d.mts +1 -1
- package/dist/cli/index.mjs +19 -18
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +42 -33
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +2 -2
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +4 -8
- package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +14 -11
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +6 -5
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +8 -13
- package/dist/presets/aws-lambda/runtime/_utils.mjs +95 -81
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -2
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +25 -27
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +7 -7
- package/dist/presets/azure/runtime/_utils.mjs +43 -43
- package/dist/presets/azure/runtime/azure-swa.d.mts +2 -2
- package/dist/presets/azure/runtime/azure-swa.mjs +22 -21
- package/dist/presets/bun/runtime/bun.d.mts +1 -0
- package/dist/presets/bun/runtime/bun.mjs +18 -17
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +10 -7
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +78 -87
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +6 -14
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +53 -58
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -7
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +12 -14
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +12 -12
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +35 -39
- package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +2 -2
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +86 -76
- package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +12 -11
- package/dist/presets/deno/runtime/deno-server.d.mts +2 -1
- package/dist/presets/deno/runtime/deno-server.mjs +31 -39
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +2 -1
- package/dist/presets/netlify/runtime/netlify-edge.mjs +14 -11
- package/dist/presets/netlify/runtime/netlify.mjs +11 -17
- package/dist/presets/node/runtime/node-cluster.mjs +49 -48
- package/dist/presets/node/runtime/node-middleware.d.mts +3 -2
- package/dist/presets/node/runtime/node-middleware.mjs +7 -6
- package/dist/presets/node/runtime/node-server.mjs +33 -23
- package/dist/presets/standard/runtime/server.d.mts +1 -3
- package/dist/presets/standard/runtime/server.mjs +1 -3
- package/dist/presets/stormkit/runtime/stormkit.d.mts +13 -13
- package/dist/presets/stormkit/runtime/stormkit.mjs +20 -20
- package/dist/presets/vercel/runtime/vercel.d.mts +3 -3
- package/dist/presets/vercel/runtime/vercel.mjs +15 -14
- package/dist/presets/winterjs/runtime/winterjs.d.mts +2 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +72 -68
- package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
- package/dist/runtime/index.d.mts +12 -1
- package/dist/runtime/index.mjs +12 -7
- package/dist/runtime/internal/app.mjs +175 -162
- package/dist/runtime/internal/cache.d.mts +10 -4
- package/dist/runtime/internal/cache.mjs +247 -216
- package/dist/runtime/internal/context.d.mts +9 -9
- package/dist/runtime/internal/context.mjs +17 -10
- package/dist/runtime/internal/database.mjs +8 -10
- package/dist/runtime/internal/error/dev.d.mts +5 -4
- package/dist/runtime/internal/error/dev.mjs +106 -105
- package/dist/runtime/internal/error/prod.d.mts +2 -2
- package/dist/runtime/internal/error/prod.mjs +48 -52
- package/dist/runtime/internal/error/utils.d.mts +4 -4
- package/dist/runtime/internal/error/utils.mjs +1 -1
- package/dist/runtime/internal/index.d.mts +2 -0
- package/dist/runtime/internal/index.mjs +2 -0
- package/dist/runtime/internal/lib/http-graceful-shutdown.d.mts +14 -14
- package/dist/runtime/internal/lib/http-graceful-shutdown.mjs +248 -209
- package/dist/runtime/internal/meta.d.mts +1 -1
- package/dist/runtime/internal/meta.mjs +1 -1
- package/dist/runtime/internal/plugin.d.mts +2 -2
- package/dist/runtime/internal/plugin.mjs +1 -1
- package/dist/runtime/internal/renderer.mjs +39 -31
- package/dist/runtime/internal/route-rules.d.mts +8 -8
- package/dist/runtime/internal/route-rules.mjs +53 -51
- package/dist/runtime/internal/routes/dev-tasks.d.mts +1 -30
- package/dist/runtime/internal/routes/dev-tasks.mjs +15 -17
- package/dist/runtime/internal/routes/openapi.d.mts +1 -0
- package/dist/runtime/internal/routes/openapi.mjs +81 -87
- package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +1 -2
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +10 -17
- package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
- package/dist/runtime/internal/routes/scalar.d.mts +1 -0
- package/dist/runtime/internal/routes/scalar.mjs +22 -23
- package/dist/runtime/internal/routes/swagger.d.mts +1 -0
- package/dist/runtime/internal/routes/swagger.mjs +9 -11
- package/dist/runtime/internal/runtime-config.d.mts +4 -4
- package/dist/runtime/internal/runtime-config.mjs +40 -35
- package/dist/runtime/internal/shutdown.d.mts +2 -7
- package/dist/runtime/internal/shutdown.mjs +30 -29
- package/dist/runtime/internal/static.mjs +63 -74
- package/dist/runtime/internal/storage.mjs +2 -2
- package/dist/runtime/internal/task.d.mts +6 -6
- package/dist/runtime/internal/task.mjs +56 -59
- package/dist/runtime/internal/utils.d.mts +1 -1
- package/dist/runtime/internal/utils.mjs +4 -10
- package/dist/types/index.d.mts +2566 -3851
- package/dist/types/index.mjs +1 -1
- package/dist/vite.d.mts +61 -51
- package/dist/vite.mjs +55 -132
- package/package.json +10 -10
- package/dist/_build/build.mjs +0 -368
- package/dist/_build/build2.mjs +0 -556
- package/dist/_build/info.mjs +0 -1002
- package/dist/_build/prepare.mjs +0 -1511
- package/dist/_build/snapshot.mjs +0 -185
- package/dist/_build/vite.mjs +0 -959
- package/dist/_build/vite2.mjs +0 -149
- package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +0 -189
- package/dist/_chunks/_deps/@jridgewell/remapping.mjs +0 -137
- package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +0 -231
- package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +0 -173
- package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +0 -170
- package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +0 -89
- package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +0 -2376
- package/dist/_chunks/_deps/@rollup/plugin-inject.mjs +0 -212
- package/dist/_chunks/_deps/@rollup/plugin-json.mjs +0 -37
- package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +0 -1386
- package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +0 -133
- package/dist/_chunks/_deps/@rollup/pluginutils.mjs +0 -346
- package/dist/_chunks/_deps/acorn.mjs +0 -6225
- package/dist/_chunks/_deps/c12.mjs +0 -510
- package/dist/_chunks/_deps/chokidar.mjs +0 -1428
- package/dist/_chunks/_deps/citty.mjs +0 -460
- package/dist/_chunks/_deps/commondir.mjs +0 -77
- package/dist/_chunks/_deps/compatx.mjs +0 -76
- package/dist/_chunks/_deps/confbox.mjs +0 -300
- package/dist/_chunks/_deps/debug.mjs +0 -885
- package/dist/_chunks/_deps/deepmerge.mjs +0 -147
- package/dist/_chunks/_deps/depd.mjs +0 -550
- package/dist/_chunks/_deps/dot-prop.mjs +0 -282
- package/dist/_chunks/_deps/dotenv.mjs +0 -555
- package/dist/_chunks/_deps/duplexer.mjs +0 -1
- package/dist/_chunks/_deps/ee-first.mjs +0 -104
- package/dist/_chunks/_deps/encodeurl.mjs +0 -69
- package/dist/_chunks/_deps/escape-html.mjs +0 -87
- package/dist/_chunks/_deps/escape-string-regexp.mjs +0 -13
- package/dist/_chunks/_deps/estree-walker.mjs +0 -433
- package/dist/_chunks/_deps/etag.mjs +0 -147
- package/dist/_chunks/_deps/exsolve.mjs +0 -1416
- package/dist/_chunks/_deps/fresh.mjs +0 -145
- package/dist/_chunks/_deps/function-bind.mjs +0 -106
- package/dist/_chunks/_deps/giget.mjs +0 -451
- package/dist/_chunks/_deps/gzip-size.mjs +0 -19
- package/dist/_chunks/_deps/hasown.mjs +0 -19
- package/dist/_chunks/_deps/http-errors.mjs +0 -307
- package/dist/_chunks/_deps/httpxy.mjs +0 -580
- package/dist/_chunks/_deps/inherits.mjs +0 -57
- package/dist/_chunks/_deps/is-core-module.mjs +0 -596
- package/dist/_chunks/_deps/is-module.mjs +0 -25
- package/dist/_chunks/_deps/is-reference.mjs +0 -31
- package/dist/_chunks/_deps/klona.mjs +0 -137
- package/dist/_chunks/_deps/knitwork.mjs +0 -172
- package/dist/_chunks/_deps/local-pkg.mjs +0 -163
- package/dist/_chunks/_deps/mime-db.mjs +0 -11685
- package/dist/_chunks/_deps/mime-types.mjs +0 -287
- package/dist/_chunks/_deps/mime.mjs +0 -1172
- package/dist/_chunks/_deps/mlly.mjs +0 -2413
- package/dist/_chunks/_deps/ms.mjs +0 -172
- package/dist/_chunks/_deps/node-fetch-native.mjs +0 -3
- package/dist/_chunks/_deps/nypm.mjs +0 -219
- package/dist/_chunks/_deps/on-finished.mjs +0 -246
- package/dist/_chunks/_deps/parseurl.mjs +0 -168
- package/dist/_chunks/_deps/path-parse.mjs +0 -85
- package/dist/_chunks/_deps/pathe.mjs +0 -251
- package/dist/_chunks/_deps/perfect-debounce.mjs +0 -88
- package/dist/_chunks/_deps/picomatch.mjs +0 -2144
- package/dist/_chunks/_deps/pkg-types.mjs +0 -247
- package/dist/_chunks/_deps/pretty-bytes.mjs +0 -180
- package/dist/_chunks/_deps/quansync.mjs +0 -99
- package/dist/_chunks/_deps/range-parser.mjs +0 -171
- package/dist/_chunks/_deps/rc9.mjs +0 -219
- package/dist/_chunks/_deps/readdirp.mjs +0 -245
- package/dist/_chunks/_deps/resolve.mjs +0 -1260
- package/dist/_chunks/_deps/send.mjs +0 -1022
- package/dist/_chunks/_deps/serve-static.mjs +0 -228
- package/dist/_chunks/_deps/setprototypeof.mjs +0 -26
- package/dist/_chunks/_deps/statuses.mjs +0 -457
- package/dist/_chunks/_deps/std-env.mjs +0 -3
- package/dist/_chunks/_deps/strip-literal.mjs +0 -67
- package/dist/_chunks/_deps/supports-color.mjs +0 -44
- package/dist/_chunks/_deps/tinyexec.mjs +0 -552
- package/dist/_chunks/_deps/toidentifier.mjs +0 -41
- package/dist/_chunks/_deps/ultrahtml.mjs +0 -3
- package/dist/_chunks/_deps/unimport.mjs +0 -2267
- package/dist/_chunks/_deps/unplugin-utils.mjs +0 -65
- package/dist/_chunks/_deps/unplugin.mjs +0 -1294
- package/dist/_chunks/_deps/untyped.mjs +0 -375
- package/dist/_chunks/_deps/unwasm.mjs +0 -6959
- package/dist/_chunks/_deps/webpack-virtual-modules.mjs +0 -360
- package/dist/_chunks/_presets/_all.mjs +0 -59
- package/dist/_chunks/_presets/_nitro.mjs +0 -74
- package/dist/_chunks/_presets/_resolve.mjs +0 -64
- package/dist/_chunks/_presets/_static.mjs +0 -69
- package/dist/_chunks/_presets/_types.mjs +0 -3
- package/dist/_chunks/_presets/_utils.mjs +0 -31
- package/dist/_chunks/_presets/alwaysdata.mjs +0 -17
- package/dist/_chunks/_presets/aws-amplify.mjs +0 -111
- package/dist/_chunks/_presets/aws-lambda.mjs +0 -23
- package/dist/_chunks/_presets/azure.mjs +0 -162
- package/dist/_chunks/_presets/bun.mjs +0 -19
- package/dist/_chunks/_presets/cleavr.mjs +0 -15
- package/dist/_chunks/_presets/cloudflare.mjs +0 -608
- package/dist/_chunks/_presets/deno.mjs +0 -196
- package/dist/_chunks/_presets/digitalocean.mjs +0 -14
- package/dist/_chunks/_presets/firebase.mjs +0 -47
- package/dist/_chunks/_presets/flightcontrol.mjs +0 -14
- package/dist/_chunks/_presets/genezio.mjs +0 -13
- package/dist/_chunks/_presets/heroku.mjs +0 -14
- package/dist/_chunks/_presets/iis.mjs +0 -194
- package/dist/_chunks/_presets/index.mjs +0 -62
- package/dist/_chunks/_presets/koyeb.mjs +0 -14
- package/dist/_chunks/_presets/netlify.mjs +0 -241
- package/dist/_chunks/_presets/node.mjs +0 -54
- package/dist/_chunks/_presets/platform.mjs +0 -14
- package/dist/_chunks/_presets/render.mjs +0 -14
- package/dist/_chunks/_presets/standard.mjs +0 -23
- package/dist/_chunks/_presets/stormkit.mjs +0 -18
- package/dist/_chunks/_presets/vercel.mjs +0 -375
- package/dist/_chunks/_presets/winterjs.mjs +0 -22
- package/dist/_chunks/_presets/zeabur.mjs +0 -69
- package/dist/_chunks/_presets/zerops.mjs +0 -27
- package/dist/_chunks/app.mjs +0 -600
- package/dist/_chunks/builder.mjs +0 -648
- package/dist/_chunks/server.mjs +0 -256
- package/dist/_cli/build.mjs +0 -49
- package/dist/_cli/common.mjs +0 -13
- package/dist/_cli/dev.mjs +0 -121
- package/dist/_cli/index.mjs +0 -16
- package/dist/_cli/list.mjs +0 -33
- package/dist/_cli/prepare.mjs +0 -23
- package/dist/_cli/run.mjs +0 -59
- package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +0 -21
- package/dist/runtime/internal/empty.d.mts +0 -0
- package/dist/runtime/internal/vite/dev-entry.d.mts +0 -1
- package/dist/runtime/internal/vite/dev-worker.d.mts +0 -1
- package/dist/runtime/internal/vite/prod-setup.d.mts +0 -4
- package/dist/runtime/internal/vite/ssr-renderer.d.mts +0 -4
- /package/lib/{indexd.mts → index.d.mts} +0 -0
|
@@ -1,580 +0,0 @@
|
|
|
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 };
|
|
@@ -1,57 +0,0 @@
|
|
|
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 };
|