@suveren/gateway 0.2.12 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -7
- package/dist/control-plane/index.mjs +146 -2
- package/dist/mcp-server/http.mjs +80 -38
- package/dist/ui/assets/index-RkZBhIxU.js +105 -0
- package/dist/ui/index.html +1 -1
- package/node_modules/@hap/core/dist/index.d.mts +147 -3
- package/node_modules/@hap/core/dist/index.d.ts +147 -3
- package/node_modules/@hap/core/dist/index.js +74 -10
- package/node_modules/@hap/core/dist/index.mjs +69 -10
- package/node_modules/@hap/core/package.json +1 -1
- package/node_modules/@hap/core/src/gatekeeper.ts +4 -4
- package/node_modules/@hap/core/src/identity.ts +77 -0
- package/node_modules/@hap/core/src/index.ts +2 -0
- package/node_modules/@hap/core/src/intent-disclosure.ts +69 -0
- package/node_modules/@hap/core/src/types.ts +62 -2
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/README.md +16 -1
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/index.js +4 -20
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/lib/read.js +17 -17
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/lib/types/json.js +60 -32
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/lib/types/raw.js +3 -3
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/lib/types/text.js +3 -3
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/lib/types/urlencoded.js +16 -20
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/lib/utils.js +18 -16
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/LICENSE +22 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/README.md +69 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/dist/index.d.ts +26 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/dist/index.js +170 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/dist/index.js.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/node_modules/content-type/package.json +52 -0
- package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/package.json +23 -10
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/assert/strict.d.ts +10 -1
- package/node_modules/@types/node/assert.d.ts +144 -17
- package/node_modules/@types/node/async_hooks.d.ts +9 -9
- package/node_modules/@types/node/buffer.d.ts +0 -5
- package/node_modules/@types/node/child_process.d.ts +17 -21
- package/node_modules/@types/node/cluster.d.ts +13 -13
- package/node_modules/@types/node/console.d.ts +1 -1
- package/node_modules/@types/node/crypto.d.ts +454 -571
- package/node_modules/@types/node/diagnostics_channel.d.ts +37 -29
- package/node_modules/@types/node/dns.d.ts +14 -14
- package/node_modules/@types/node/events.d.ts +3 -3
- package/node_modules/@types/node/fs/promises.d.ts +4 -4
- package/node_modules/@types/node/fs.d.ts +3 -12
- package/node_modules/@types/node/globals.d.ts +4 -4
- package/node_modules/@types/node/http.d.ts +5 -5
- package/node_modules/@types/node/http2.d.ts +5 -1
- package/node_modules/@types/node/index.d.ts +0 -3
- package/node_modules/@types/node/inspector.d.ts +1 -1
- package/node_modules/@types/node/module.d.ts +16 -45
- package/node_modules/@types/node/net.d.ts +1 -1
- package/node_modules/@types/node/os.d.ts +2 -2
- package/node_modules/@types/node/package.json +4 -4
- package/node_modules/@types/node/perf_hooks.d.ts +1 -9
- package/node_modules/@types/node/process.d.ts +11 -11
- package/node_modules/@types/node/readline.d.ts +12 -11
- package/node_modules/@types/node/repl.d.ts +10 -10
- package/node_modules/@types/node/sqlite.d.ts +1 -1
- package/node_modules/@types/node/stream/promises.d.ts +2 -2
- package/node_modules/@types/node/stream/web.d.ts +1 -1
- package/node_modules/@types/node/stream.d.ts +5 -5
- package/node_modules/@types/node/test/reporters.d.ts +1 -1
- package/node_modules/@types/node/test.d.ts +8 -8
- package/node_modules/@types/node/tls.d.ts +1 -1
- package/node_modules/@types/node/ts5.6/index.d.ts +1 -4
- package/node_modules/@types/node/ts5.7/index.d.ts +0 -3
- package/node_modules/@types/node/url.d.ts +3 -3
- package/node_modules/@types/node/util/types.d.ts +1 -1
- package/node_modules/@types/node/util.d.ts +3 -20
- package/node_modules/@types/node/v8.d.ts +1 -1
- package/node_modules/@types/node/vm.d.ts +9 -9
- package/node_modules/@types/node/web-globals/domexception.d.ts +15 -0
- package/node_modules/@types/node/worker_threads.d.ts +2 -5
- package/node_modules/@types/node/zlib.d.ts +3 -3
- package/node_modules/fast-uri/index.js +1 -1
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/fast-uri/test/security.test.js +28 -0
- package/node_modules/hono/dist/adapter/aws-lambda/handler.js +14 -20
- package/node_modules/hono/dist/adapter/lambda-edge/handler.js +8 -2
- package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +14 -20
- package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +8 -2
- package/node_modules/hono/dist/cjs/helper/css/common.js +3 -1
- package/node_modules/hono/dist/cjs/helper/css/index.js +9 -1
- package/node_modules/hono/dist/cjs/jsx/base.js +8 -14
- package/node_modules/hono/dist/cjs/jsx/components.js +41 -21
- package/node_modules/hono/dist/cjs/jsx/context.js +131 -5
- package/node_modules/hono/dist/cjs/jsx/streaming.js +9 -7
- package/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/cors/index.js +2 -5
- package/node_modules/hono/dist/cjs/middleware/language/language.js +10 -32
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/timing/timing.js +3 -1
- package/node_modules/hono/dist/cjs/utils/ipaddr.js +6 -1
- package/node_modules/hono/dist/helper/css/common.js +3 -1
- package/node_modules/hono/dist/helper/css/index.js +9 -1
- package/node_modules/hono/dist/jsx/base.js +15 -15
- package/node_modules/hono/dist/jsx/components.js +42 -22
- package/node_modules/hono/dist/jsx/context.js +129 -5
- package/node_modules/hono/dist/jsx/streaming.js +10 -8
- package/node_modules/hono/dist/middleware/bearer-auth/index.js +1 -1
- package/node_modules/hono/dist/middleware/cors/index.js +2 -5
- package/node_modules/hono/dist/middleware/language/language.js +10 -32
- package/node_modules/hono/dist/middleware/serve-static/index.js +1 -1
- package/node_modules/hono/dist/middleware/timing/timing.js +3 -1
- package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +1 -1
- package/node_modules/hono/dist/types/adapter/aws-lambda/handler.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/base.d.ts +1 -3
- package/node_modules/hono/dist/types/jsx/context.d.ts +39 -0
- package/node_modules/hono/dist/utils/ipaddr.js +6 -1
- package/node_modules/hono/package.json +19 -13
- package/node_modules/http-proxy-middleware/README.md +3 -10
- package/node_modules/http-proxy-middleware/dist/errors.d.ts +4 -0
- package/node_modules/http-proxy-middleware/dist/errors.js +16 -1
- package/node_modules/http-proxy-middleware/dist/factory.d.ts +2 -2
- package/node_modules/http-proxy-middleware/dist/handlers/fix-request-body-utils/stringify-form-data.d.ts +7 -0
- package/node_modules/http-proxy-middleware/dist/handlers/fix-request-body-utils/stringify-form-data.js +45 -0
- package/node_modules/http-proxy-middleware/dist/handlers/fix-request-body.d.ts +1 -1
- package/node_modules/http-proxy-middleware/dist/handlers/fix-request-body.js +23 -23
- package/node_modules/http-proxy-middleware/dist/handlers/response-interceptor.d.ts +1 -1
- package/node_modules/http-proxy-middleware/dist/handlers/response-interceptor.js +1 -1
- package/node_modules/http-proxy-middleware/dist/http-proxy-middleware.d.ts +1 -1
- package/node_modules/http-proxy-middleware/dist/http-proxy-middleware.js +2 -2
- package/node_modules/http-proxy-middleware/dist/legacy/create-proxy-middleware.d.ts +1 -1
- package/node_modules/http-proxy-middleware/dist/legacy/create-proxy-middleware.js +1 -1
- package/node_modules/http-proxy-middleware/dist/legacy/options-adapter.js +1 -1
- package/node_modules/http-proxy-middleware/dist/legacy/types.d.ts +1 -1
- package/node_modules/http-proxy-middleware/dist/path-filter.d.ts +1 -1
- package/node_modules/http-proxy-middleware/dist/path-filter.js +1 -1
- package/node_modules/http-proxy-middleware/dist/path-rewriter.js +1 -1
- package/node_modules/http-proxy-middleware/dist/plugins/default/error-response-plugin.js +2 -1
- package/node_modules/http-proxy-middleware/dist/plugins/default/logger-plugin.js +3 -3
- package/node_modules/http-proxy-middleware/dist/router.js +26 -8
- package/node_modules/http-proxy-middleware/dist/status-code.js +15 -12
- package/node_modules/http-proxy-middleware/dist/types.d.ts +3 -3
- package/node_modules/http-proxy-middleware/dist/types.js +0 -4
- package/node_modules/http-proxy-middleware/dist/utils/sanitize.d.ts +1 -0
- package/node_modules/http-proxy-middleware/dist/utils/sanitize.js +6 -0
- package/node_modules/http-proxy-middleware/package.json +30 -28
- package/node_modules/qs/CHANGELOG.md +11 -0
- package/node_modules/qs/dist/qs.js +17 -17
- package/node_modules/qs/lib/parse.js +19 -8
- package/node_modules/qs/lib/utils.js +47 -8
- package/node_modules/qs/package.json +6 -5
- package/node_modules/qs/test/parse.js +230 -0
- package/node_modules/qs/test/utils.js +194 -0
- package/node_modules/side-channel/CHANGELOG.md +10 -0
- package/node_modules/side-channel/README.md +1 -1
- package/node_modules/side-channel/index.js +5 -2
- package/node_modules/side-channel/package.json +10 -10
- package/node_modules/side-channel/test/index.js +16 -0
- package/node_modules/undici-types/agent.d.ts +0 -2
- package/node_modules/undici-types/client.d.ts +25 -19
- package/node_modules/undici-types/dispatcher.d.ts +7 -33
- package/node_modules/undici-types/dispatcher1-wrapper.d.ts +7 -0
- package/node_modules/undici-types/fetch.d.ts +24 -4
- package/node_modules/undici-types/h2c-client.d.ts +6 -6
- package/node_modules/undici-types/handlers.d.ts +1 -2
- package/node_modules/undici-types/header.d.ts +5 -0
- package/node_modules/undici-types/index.d.ts +3 -1
- package/node_modules/undici-types/interceptors.d.ts +1 -1
- package/node_modules/undici-types/package.json +1 -1
- package/node_modules/undici-types/pool.d.ts +0 -2
- package/node_modules/undici-types/proxy-agent.d.ts +2 -2
- package/node_modules/undici-types/round-robin-pool.d.ts +0 -2
- package/node_modules/undici-types/snapshot-agent.d.ts +4 -0
- package/node_modules/undici-types/socks5-proxy-agent.d.ts +2 -2
- package/node_modules/undici-types/webidl.d.ts +0 -1
- package/package.json +3 -3
- package/dist/ui/assets/index-CS16uhqb.js +0 -102
- package/node_modules/@types/node/compatibility/iterators.d.ts +0 -21
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.27",
|
|
4
4
|
"description": "Web framework built on Web Standards",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"watch": "bun run --shell bun remove-dist && bun ./build/build.ts --watch && bun run copy:package.cjs.json",
|
|
32
32
|
"coverage": "vitest --run --coverage",
|
|
33
33
|
"prerelease": "bun test:deno && bun run build",
|
|
34
|
-
"release": "np",
|
|
34
|
+
"release": "np --no-publish",
|
|
35
35
|
"remove-dist": "rm -rf dist"
|
|
36
36
|
},
|
|
37
37
|
"exports": {
|
|
@@ -506,9 +506,18 @@
|
|
|
506
506
|
"jsx/dom/server": [
|
|
507
507
|
"./dist/types/jsx/dom/server.d.ts"
|
|
508
508
|
],
|
|
509
|
+
"jsx/dom/jsx-dev-runtime": [
|
|
510
|
+
"./dist/types/jsx/dom/jsx-dev-runtime.d.ts"
|
|
511
|
+
],
|
|
512
|
+
"jsx/dom/jsx-runtime": [
|
|
513
|
+
"./dist/types/jsx/dom/jsx-runtime.d.ts"
|
|
514
|
+
],
|
|
509
515
|
"jwt": [
|
|
510
516
|
"./dist/types/middleware/jwt"
|
|
511
517
|
],
|
|
518
|
+
"jwk": [
|
|
519
|
+
"./dist/types/middleware/jwk"
|
|
520
|
+
],
|
|
512
521
|
"timeout": [
|
|
513
522
|
"./dist/types/middleware/timeout"
|
|
514
523
|
],
|
|
@@ -552,19 +561,19 @@
|
|
|
552
561
|
"./dist/types/router.d.ts"
|
|
553
562
|
],
|
|
554
563
|
"router/reg-exp-router": [
|
|
555
|
-
"./dist/types/router/reg-exp-router
|
|
564
|
+
"./dist/types/router/reg-exp-router"
|
|
556
565
|
],
|
|
557
566
|
"router/smart-router": [
|
|
558
|
-
"./dist/types/router/smart-router
|
|
567
|
+
"./dist/types/router/smart-router"
|
|
559
568
|
],
|
|
560
569
|
"router/trie-router": [
|
|
561
|
-
"./dist/types/router/trie-router
|
|
570
|
+
"./dist/types/router/trie-router"
|
|
562
571
|
],
|
|
563
572
|
"router/pattern-router": [
|
|
564
|
-
"./dist/types/router/pattern-router
|
|
573
|
+
"./dist/types/router/pattern-router"
|
|
565
574
|
],
|
|
566
575
|
"router/linear-router": [
|
|
567
|
-
"./dist/types/router/linear-router
|
|
576
|
+
"./dist/types/router/linear-router"
|
|
568
577
|
],
|
|
569
578
|
"utils/jwt": [
|
|
570
579
|
"./dist/types/utils/jwt/index.d.ts"
|
|
@@ -596,15 +605,15 @@
|
|
|
596
605
|
"bun": [
|
|
597
606
|
"./dist/types/adapter/bun"
|
|
598
607
|
],
|
|
599
|
-
"nextjs": [
|
|
600
|
-
"./dist/types/adapter/nextjs"
|
|
601
|
-
],
|
|
602
608
|
"aws-lambda": [
|
|
603
609
|
"./dist/types/adapter/aws-lambda"
|
|
604
610
|
],
|
|
605
611
|
"vercel": [
|
|
606
612
|
"./dist/types/adapter/vercel"
|
|
607
613
|
],
|
|
614
|
+
"netlify": [
|
|
615
|
+
"./dist/types/adapter/netlify"
|
|
616
|
+
],
|
|
608
617
|
"lambda-edge": [
|
|
609
618
|
"./dist/types/adapter/lambda-edge"
|
|
610
619
|
],
|
|
@@ -658,18 +667,15 @@
|
|
|
658
667
|
"devDependencies": {
|
|
659
668
|
"@hono/eslint-config": "^2.1.0",
|
|
660
669
|
"@hono/node-server": "^2.0.2",
|
|
661
|
-
"@types/glob": "^9.0.0",
|
|
662
670
|
"@types/jsdom": "^21.1.7",
|
|
663
671
|
"@types/node": "^24.3.0",
|
|
664
672
|
"@types/ws": "^8.18.1",
|
|
665
673
|
"@typescript/native-preview": "7.0.0-dev.20260210.1",
|
|
666
674
|
"@vitest/coverage-v8": "^4.1.7",
|
|
667
|
-
"arg": "^5.0.2",
|
|
668
675
|
"bun-types": "^1.2.20",
|
|
669
676
|
"editorconfig-checker": "6.1.1",
|
|
670
677
|
"esbuild": "^0.27.1",
|
|
671
678
|
"eslint": "^9.39.3",
|
|
672
|
-
"glob": "^11.0.0",
|
|
673
679
|
"jsdom": "22.1.0",
|
|
674
680
|
"msw": "^2.6.0",
|
|
675
681
|
"np": "10.2.0",
|
|
@@ -28,10 +28,8 @@ Proxy `/api` requests to `http://www.example.org`
|
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
30
|
// typescript
|
|
31
|
-
|
|
32
31
|
import * as express from 'express';
|
|
33
|
-
import type { Request, Response
|
|
34
|
-
|
|
32
|
+
import type { NextFunction, Request, Response } from 'express';
|
|
35
33
|
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
36
34
|
import type { Filter, Options, RequestHandler } from 'http-proxy-middleware';
|
|
37
35
|
|
|
@@ -163,18 +161,15 @@ http-proxy-middleware options:
|
|
|
163
161
|
Narrow down which requests should be proxied. The `path` used for filtering is the `request.url` pathname. In Express, this is the `path` relative to the mount-point of the proxy.
|
|
164
162
|
|
|
165
163
|
- **path matching**
|
|
166
|
-
|
|
167
164
|
- `createProxyMiddleware({...})` - matches any path, all requests will be proxied when `pathFilter` is not configured.
|
|
168
165
|
- `createProxyMiddleware({ pathFilter: '/api', ...})` - matches paths starting with `/api`
|
|
169
166
|
|
|
170
167
|
- **multiple path matching**
|
|
171
|
-
|
|
172
168
|
- `createProxyMiddleware({ pathFilter: ['/api', '/ajax', '/someotherpath'], ...})`
|
|
173
169
|
|
|
174
170
|
- **wildcard path matching**
|
|
175
171
|
|
|
176
172
|
For fine-grained control you can use wildcard matching. Glob pattern matching is done by _micromatch_. Visit [micromatch](https://www.npmjs.com/package/micromatch) or [glob](https://www.npmjs.com/package/glob) for more globbing examples.
|
|
177
|
-
|
|
178
173
|
- `createProxyMiddleware({ pathFilter: '**', ...})` matches any path, all requests will be proxied.
|
|
179
174
|
- `createProxyMiddleware({ pathFilter: '**/*.html', ...})` matches any path which ends with `.html`
|
|
180
175
|
- `createProxyMiddleware({ pathFilter: '/*.html', ...})` matches paths directly under path-absolute
|
|
@@ -418,13 +413,12 @@ The following options are provided by the underlying [http-proxy](https://github
|
|
|
418
413
|
- **option.autoRewrite**: rewrites the location host/port on (301/302/307/308) redirects based on requested host/port. Default: false.
|
|
419
414
|
- **option.protocolRewrite**: rewrites the location protocol on (301/302/307/308) redirects to 'http' or 'https'. Default: null.
|
|
420
415
|
- **option.cookieDomainRewrite**: rewrites domain of `set-cookie` headers. Possible values:
|
|
421
|
-
|
|
422
416
|
- `false` (default): disable cookie rewriting
|
|
423
417
|
- String: new domain, for example `cookieDomainRewrite: "new.domain"`. To remove the domain, use `cookieDomainRewrite: ""`.
|
|
424
418
|
- Object: mapping of domains to new domains, use `"*"` to match all domains.
|
|
425
419
|
For example keep one domain unchanged, rewrite one domain and remove other domains:
|
|
426
420
|
|
|
427
|
-
```
|
|
421
|
+
```jsonc
|
|
428
422
|
cookieDomainRewrite: {
|
|
429
423
|
"unchanged.domain": "unchanged.domain",
|
|
430
424
|
"old.domain": "new.domain",
|
|
@@ -433,13 +427,12 @@ The following options are provided by the underlying [http-proxy](https://github
|
|
|
433
427
|
```
|
|
434
428
|
|
|
435
429
|
- **option.cookiePathRewrite**: rewrites path of `set-cookie` headers. Possible values:
|
|
436
|
-
|
|
437
430
|
- `false` (default): disable cookie rewriting
|
|
438
431
|
- String: new path, for example `cookiePathRewrite: "/newPath/"`. To remove the path, use `cookiePathRewrite: ""`. To set path to root use `cookiePathRewrite: "/"`.
|
|
439
432
|
- Object: mapping of paths to new paths, use `"*"` to match all paths.
|
|
440
433
|
For example, to keep one path unchanged, rewrite one path and remove other paths:
|
|
441
434
|
|
|
442
|
-
```
|
|
435
|
+
```jsonc
|
|
443
436
|
cookiePathRewrite: {
|
|
444
437
|
"/unchanged.path/": "/unchanged.path/",
|
|
445
438
|
"/old.path/": "/new.path/",
|
|
@@ -4,3 +4,7 @@ export declare enum ERRORS {
|
|
|
4
4
|
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\"].",
|
|
5
5
|
ERR_PATH_REWRITER_CONFIG = "[HPM] Invalid pathRewrite config. Expecting object with pathRewrite config or a rewrite function"
|
|
6
6
|
}
|
|
7
|
+
export declare class HttpProxyMiddlewareError extends Error {
|
|
8
|
+
code: string;
|
|
9
|
+
constructor(message: string, code: string);
|
|
10
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ERRORS = void 0;
|
|
3
|
+
exports.HttpProxyMiddlewareError = exports.ERRORS = void 0;
|
|
4
4
|
var ERRORS;
|
|
5
5
|
(function (ERRORS) {
|
|
6
6
|
ERRORS["ERR_CONFIG_FACTORY_TARGET_MISSING"] = "[HPM] Missing \"target\" option. Example: {target: \"http://www.example.org\"}";
|
|
@@ -8,3 +8,18 @@ var ERRORS;
|
|
|
8
8
|
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\"].";
|
|
9
9
|
ERRORS["ERR_PATH_REWRITER_CONFIG"] = "[HPM] Invalid pathRewrite config. Expecting object with pathRewrite config or a rewrite function";
|
|
10
10
|
})(ERRORS || (exports.ERRORS = ERRORS = {}));
|
|
11
|
+
class HttpProxyMiddlewareError extends Error {
|
|
12
|
+
constructor(message, code) {
|
|
13
|
+
super(message);
|
|
14
|
+
// add custom `code` property
|
|
15
|
+
// so this can be used in src/plugins/default/error-response-plugin.ts to determine the status code to return
|
|
16
|
+
this.code = code;
|
|
17
|
+
// set the correct name for the error class
|
|
18
|
+
this.name = this.constructor.name;
|
|
19
|
+
// maintain proper stack trace (V8 environments)
|
|
20
|
+
if (Error.captureStackTrace) {
|
|
21
|
+
Error.captureStackTrace(this, this.constructor);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.HttpProxyMiddlewareError = HttpProxyMiddlewareError;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import type * as http from 'node:http';
|
|
2
|
+
import type { NextFunction, Options, RequestHandler } from './types';
|
|
3
3
|
export declare function createProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction>(options: Options<TReq, TRes>): RequestHandler<TReq, TRes, TNext>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringifyFormData = stringifyFormData;
|
|
4
|
+
const errors_1 = require("../../errors");
|
|
5
|
+
const CR_OR_LF = /[\r\n]/;
|
|
6
|
+
const ERROR_CODE_PREFIX = 'HPM_ERR_INVALID_MULTIPART';
|
|
7
|
+
/**
|
|
8
|
+
* stringify FormData data
|
|
9
|
+
* @param contentType
|
|
10
|
+
* @param data
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
function stringifyFormData(contentType, data) {
|
|
14
|
+
const boundary = getMultipartBoundary(contentType);
|
|
15
|
+
let str = '';
|
|
16
|
+
for (const [key, value] of Object.entries(data)) {
|
|
17
|
+
const normalizedKey = String(key);
|
|
18
|
+
const normalizedValue = String(value);
|
|
19
|
+
// Reject potentially dangerous sequences to prevent multipart header/body injection.
|
|
20
|
+
validateMultipartField(normalizedKey, normalizedValue, boundary);
|
|
21
|
+
str += `--${boundary}\r\nContent-Disposition: form-data; name="${escapeMultipartFieldName(normalizedKey)}"\r\n\r\n${normalizedValue}\r\n`;
|
|
22
|
+
}
|
|
23
|
+
return str;
|
|
24
|
+
}
|
|
25
|
+
function getMultipartBoundary(contentType) {
|
|
26
|
+
const boundaryMatch = /(?:^|;)\s*boundary=(?:"([^"]+)"|([^;]+))/i.exec(contentType);
|
|
27
|
+
// Keep backward-compatible behavior when boundary is omitted: fall back to legacy extraction.
|
|
28
|
+
const boundary = (boundaryMatch?.[1] ?? boundaryMatch?.[2] ?? contentType).trim();
|
|
29
|
+
if (!boundary || CR_OR_LF.test(boundary)) {
|
|
30
|
+
throw new errors_1.HttpProxyMiddlewareError('[HPM] invalid multipart boundary detected.', `${ERROR_CODE_PREFIX}_BOUNDARY`);
|
|
31
|
+
}
|
|
32
|
+
return boundary;
|
|
33
|
+
}
|
|
34
|
+
function validateMultipartField(fieldName, fieldValue, boundary) {
|
|
35
|
+
const boundaryDelimiter = `--${boundary}`;
|
|
36
|
+
if (CR_OR_LF.test(fieldName)) {
|
|
37
|
+
throw new errors_1.HttpProxyMiddlewareError(`[HPM] invalid multipart field name "${fieldName}" detected.`, `${ERROR_CODE_PREFIX}_FIELD_NAME`);
|
|
38
|
+
}
|
|
39
|
+
if (CR_OR_LF.test(fieldValue) || fieldValue.includes(boundaryDelimiter)) {
|
|
40
|
+
throw new errors_1.HttpProxyMiddlewareError(`[HPM] invalid multipart field value for "${fieldName}" detected.`, `${ERROR_CODE_PREFIX}_FIELD_VALUE`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function escapeMultipartFieldName(fieldName) {
|
|
44
|
+
return fieldName.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
45
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fixRequestBody = fixRequestBody;
|
|
4
|
-
const querystring = require("querystring");
|
|
4
|
+
const querystring = require("node:querystring");
|
|
5
|
+
const stringify_form_data_1 = require("./fix-request-body-utils/stringify-form-data");
|
|
5
6
|
/**
|
|
6
7
|
* Fix proxied body if bodyParser is involved.
|
|
7
8
|
*/
|
|
@@ -22,29 +23,28 @@ function fixRequestBody(proxyReq, req) {
|
|
|
22
23
|
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
23
24
|
proxyReq.write(bodyData);
|
|
24
25
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
try {
|
|
27
|
+
// Use if-elseif to prevent multiple writeBody/setHeader calls:
|
|
28
|
+
// Error: "Cannot set headers after they are sent to the client"
|
|
29
|
+
if (contentType.includes('application/json') || contentType.includes('+json')) {
|
|
30
|
+
writeBody(JSON.stringify(requestBody));
|
|
31
|
+
}
|
|
32
|
+
else if (contentType.includes('application/x-www-form-urlencoded')) {
|
|
33
|
+
writeBody(querystring.stringify(requestBody));
|
|
34
|
+
}
|
|
35
|
+
else if (contentType.includes('multipart/form-data')) {
|
|
36
|
+
writeBody((0, stringify_form_data_1.stringifyFormData)(contentType, requestBody));
|
|
37
|
+
}
|
|
38
|
+
else if (contentType.includes('text/plain')) {
|
|
39
|
+
writeBody(requestBody);
|
|
40
|
+
}
|
|
29
41
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
writeBody(handlerFormDataBodyData(contentType, requestBody));
|
|
42
|
+
catch (error) {
|
|
43
|
+
// proxyReq listeners run outside the middleware try/catch path; re-throwing here can bubble as
|
|
44
|
+
// an unhandled exception in consumers, so destroy() is used to fail closed through proxy error handling.
|
|
45
|
+
proxyReq.destroy(toError(error));
|
|
35
46
|
}
|
|
36
47
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* @param contentType
|
|
40
|
-
* @param data
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
function handlerFormDataBodyData(contentType, data) {
|
|
44
|
-
const boundary = contentType.replace(/^.*boundary=(.*)$/, '$1');
|
|
45
|
-
let str = '';
|
|
46
|
-
for (const [key, value] of Object.entries(data)) {
|
|
47
|
-
str += `--${boundary}\r\nContent-Disposition: form-data; name="${key}"\r\n\r\n${value}\r\n`;
|
|
48
|
-
}
|
|
49
|
-
return str;
|
|
48
|
+
function toError(error) {
|
|
49
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
50
50
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type * as http from 'http';
|
|
1
|
+
import type * as http from 'node:http';
|
|
2
2
|
type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes: TReq, req: TReq, res: TRes) => Promise<Buffer | string>;
|
|
3
3
|
/**
|
|
4
4
|
* Intercept responses from upstream.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.responseInterceptor = responseInterceptor;
|
|
4
|
-
const zlib = require("zlib");
|
|
4
|
+
const zlib = require("node:zlib");
|
|
5
5
|
const debug_1 = require("../debug");
|
|
6
6
|
const function_1 = require("../utils/function");
|
|
7
7
|
const debug = debug_1.Debug.extend('response-interceptor');
|
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HttpProxyMiddleware = void 0;
|
|
4
4
|
const httpProxy = require("http-proxy");
|
|
5
5
|
const configuration_1 = require("./configuration");
|
|
6
|
+
const debug_1 = require("./debug");
|
|
6
7
|
const get_plugins_1 = require("./get-plugins");
|
|
8
|
+
const logger_1 = require("./logger");
|
|
7
9
|
const path_filter_1 = require("./path-filter");
|
|
8
10
|
const PathRewriter = require("./path-rewriter");
|
|
9
11
|
const Router = require("./router");
|
|
10
|
-
const debug_1 = require("./debug");
|
|
11
12
|
const function_1 = require("./utils/function");
|
|
12
|
-
const logger_1 = require("./logger");
|
|
13
13
|
class HttpProxyMiddleware {
|
|
14
14
|
constructor(options) {
|
|
15
15
|
this.wsInternalSubscribed = false;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.legacyCreateProxyMiddleware = legacyCreateProxyMiddleware;
|
|
4
|
-
const factory_1 = require("../factory");
|
|
5
4
|
const debug_1 = require("../debug");
|
|
5
|
+
const factory_1 = require("../factory");
|
|
6
6
|
const options_adapter_1 = require("./options-adapter");
|
|
7
7
|
const debug = debug_1.Debug.extend('legacy-create-proxy-middleware');
|
|
8
8
|
function legacyCreateProxyMiddleware(legacyContext, legacyOptions) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.legacyOptionsAdapter = legacyOptionsAdapter;
|
|
4
|
-
const url = require("url");
|
|
4
|
+
const url = require("node:url");
|
|
5
5
|
const debug_1 = require("../debug");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
7
7
|
const debug = debug_1.Debug.extend('legacy-options-adapter');
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
+
import type * as http from 'node:http';
|
|
1
2
|
import type { Filter } from './types';
|
|
2
|
-
import type * as http from 'http';
|
|
3
3
|
export declare function matchPathFilter<TReq = http.IncomingMessage>(pathFilter: Filter<TReq> | undefined, uri: string | undefined, req: http.IncomingMessage): boolean;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.matchPathFilter = matchPathFilter;
|
|
4
|
+
const url = require("node:url");
|
|
4
5
|
const isGlob = require("is-glob");
|
|
5
6
|
const micromatch = require("micromatch");
|
|
6
|
-
const url = require("url");
|
|
7
7
|
const errors_1 = require("./errors");
|
|
8
8
|
function matchPathFilter(pathFilter = '/', uri, req) {
|
|
9
9
|
// single path
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPathRewriter = createPathRewriter;
|
|
4
4
|
const is_plain_object_1 = require("is-plain-object");
|
|
5
|
-
const errors_1 = require("./errors");
|
|
6
5
|
const debug_1 = require("./debug");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
7
|
const debug = debug_1.Debug.extend('path-rewriter');
|
|
8
8
|
/**
|
|
9
9
|
* Create rewrite function, to cache parsed rewrite rules.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.errorResponsePlugin = void 0;
|
|
4
4
|
const status_code_1 = require("../../status-code");
|
|
5
|
+
const sanitize_1 = require("../../utils/sanitize");
|
|
5
6
|
function isResponseLike(obj) {
|
|
6
7
|
return obj && typeof obj.writeHead === 'function';
|
|
7
8
|
}
|
|
@@ -20,7 +21,7 @@ const errorResponsePlugin = (proxyServer, options) => {
|
|
|
20
21
|
res.writeHead(statusCode);
|
|
21
22
|
}
|
|
22
23
|
const host = req.headers && req.headers.host;
|
|
23
|
-
res.end(`Error occurred while trying to proxy: ${host}${req.url}`);
|
|
24
|
+
res.end(`Error occurred while trying to proxy: ${(0, sanitize_1.sanitize)(host)}${(0, sanitize_1.sanitize)(req.url)}`);
|
|
24
25
|
}
|
|
25
26
|
else if (isSocketLike(res)) {
|
|
26
27
|
res.destroy();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loggerPlugin = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_url_1 = require("node:url");
|
|
5
5
|
const logger_1 = require("../../logger");
|
|
6
6
|
const logger_plugin_1 = require("../../utils/logger-plugin");
|
|
7
7
|
const loggerPlugin = (proxyServer, options) => {
|
|
@@ -34,7 +34,7 @@ const loggerPlugin = (proxyServer, options) => {
|
|
|
34
34
|
host: proxyRes.req.host,
|
|
35
35
|
pathname: proxyRes.req.path,
|
|
36
36
|
};
|
|
37
|
-
target = new
|
|
37
|
+
target = new node_url_1.URL(`${obj.protocol}//${obj.host}${obj.pathname}`);
|
|
38
38
|
if (port) {
|
|
39
39
|
target.port = port;
|
|
40
40
|
}
|
|
@@ -43,7 +43,7 @@ const loggerPlugin = (proxyServer, options) => {
|
|
|
43
43
|
catch (err) {
|
|
44
44
|
// nock issue (https://github.com/chimurai/http-proxy-middleware/issues/1035)
|
|
45
45
|
// fallback to old implementation (less correct - without port)
|
|
46
|
-
target = new
|
|
46
|
+
target = new node_url_1.URL(options.target);
|
|
47
47
|
target.pathname = proxyRes.req.path;
|
|
48
48
|
}
|
|
49
49
|
const targetUrl = target.toString();
|
|
@@ -17,16 +17,27 @@ async function getTarget(req, config) {
|
|
|
17
17
|
}
|
|
18
18
|
function getTargetFromProxyTable(req, table) {
|
|
19
19
|
let result;
|
|
20
|
-
const host = req.headers.host;
|
|
21
|
-
const path = req.url;
|
|
22
|
-
const hostAndPath = host + path;
|
|
20
|
+
const host = req.headers.host || '';
|
|
21
|
+
const path = req.url || '';
|
|
23
22
|
for (const [key, value] of Object.entries(table)) {
|
|
24
23
|
if (containsPath(key)) {
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
if (isHostAndPathKey(key)) {
|
|
25
|
+
const [keyHost, keyPath] = splitHostAndPathKey(key);
|
|
26
|
+
// SECURITY: host+path keys must match exact host + path prefix.
|
|
27
|
+
if (host === keyHost && path.startsWith(keyPath)) {
|
|
28
|
+
// match 'localhost:3000/api'
|
|
29
|
+
result = value;
|
|
30
|
+
debug('match: "%s" -> "%s"', key, result);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (path.startsWith(key)) {
|
|
36
|
+
// match '/api'
|
|
37
|
+
result = value;
|
|
38
|
+
debug('match: "%s" -> "%s"', key, result);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
30
41
|
}
|
|
31
42
|
}
|
|
32
43
|
else {
|
|
@@ -43,3 +54,10 @@ function getTargetFromProxyTable(req, table) {
|
|
|
43
54
|
function containsPath(v) {
|
|
44
55
|
return v.indexOf('/') > -1;
|
|
45
56
|
}
|
|
57
|
+
function isHostAndPathKey(v) {
|
|
58
|
+
return containsPath(v) && !v.startsWith('/');
|
|
59
|
+
}
|
|
60
|
+
function splitHostAndPathKey(v) {
|
|
61
|
+
const firstSlash = v.indexOf('/');
|
|
62
|
+
return [v.slice(0, firstSlash), v.slice(firstSlash)];
|
|
63
|
+
}
|
|
@@ -5,19 +5,22 @@ function getStatusCode(errorCode) {
|
|
|
5
5
|
let statusCode;
|
|
6
6
|
if (/HPE_INVALID/.test(errorCode)) {
|
|
7
7
|
statusCode = 502;
|
|
8
|
+
return statusCode;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
if (/HPM_ERR_INVALID_MULTIPART_/.test(errorCode)) {
|
|
11
|
+
statusCode = 400;
|
|
12
|
+
return statusCode;
|
|
13
|
+
}
|
|
14
|
+
switch (errorCode) {
|
|
15
|
+
case 'ECONNRESET':
|
|
16
|
+
case 'ENOTFOUND':
|
|
17
|
+
case 'ECONNREFUSED':
|
|
18
|
+
case 'ETIMEDOUT':
|
|
19
|
+
statusCode = 504;
|
|
20
|
+
break;
|
|
21
|
+
default:
|
|
22
|
+
statusCode = 500;
|
|
23
|
+
break;
|
|
21
24
|
}
|
|
22
25
|
return statusCode;
|
|
23
26
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Based on definition by DefinitelyTyped:
|
|
3
3
|
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
|
|
4
4
|
*/
|
|
5
|
-
import type * as http from 'http';
|
|
5
|
+
import type * as http from 'node:http';
|
|
6
|
+
import type * as net from 'node:net';
|
|
6
7
|
import type * as httpProxy from 'http-proxy';
|
|
7
|
-
import type * as net from 'net';
|
|
8
8
|
export type NextFunction<T = (err?: any) => void> = T;
|
|
9
9
|
export interface RequestHandler<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction> {
|
|
10
10
|
(req: TReq, res: TRes, next?: TNext): Promise<void>;
|
|
@@ -118,5 +118,5 @@ export interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse
|
|
|
118
118
|
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/logger.md
|
|
119
119
|
* @since v3.0.0
|
|
120
120
|
*/
|
|
121
|
-
logger?: Logger
|
|
121
|
+
logger?: Logger;
|
|
122
122
|
}
|
|
@@ -1,6 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Based on definition by DefinitelyTyped:
|
|
4
|
-
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
|
|
5
|
-
*/
|
|
6
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sanitize(input: string | undefined): string;
|