acrylblends 0.6.0 → 0.6.2
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 +8 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/docs/framework/UPSTREAM.md +1 -1
- package/docs/framework/api/presets.md +0 -3
- package/docs/framework/cordis/acryl-in-a-cordis-app.md +3 -0
- package/docs/framework/getting-started/basic.md +4 -4
- package/docs/framework/guides/jsx.md +1 -1
- package/docs/framework/guides/middleware.md +1 -1
- package/docs/framework/helpers/cookie.md +1 -1
- package/docs/framework/helpers/dev.md +0 -3
- package/docs/framework/helpers/jwt.md +1 -1
- package/docs/framework/helpers/proxy.md +0 -3
- package/docs/framework/middleware/builtin/basic-auth.md +6 -6
- package/docs/framework/middleware/builtin/cache.md +0 -3
- package/docs/framework/middleware/builtin/combine.md +1 -1
- package/docs/framework/middleware/builtin/ip-restriction.md +1 -1
- package/docs/framework/middleware/builtin/logger.md +1 -1
- package/docs/framework/middleware/builtin/mount.md +0 -3
- package/docs/framework/upstream.json +2 -2
- package/lib/accepts.d.ts +1 -1
- package/lib/acryl-base.d.ts +1 -1
- package/lib/adapter.d.ts +1 -1
- package/lib/{app-CmAYW1Al.d.ts → app-BdrVHBlJ.d.ts} +1 -1
- package/lib/basic-auth.d.ts +1 -1
- package/lib/bearer-auth.d.ts +1 -1
- package/lib/body-limit.d.ts +1 -1
- package/lib/cache.d.ts +43 -0
- package/lib/cache.js +169 -0
- package/lib/client.d.ts +2 -2
- package/lib/combine.d.ts +1 -1
- package/lib/compress.d.ts +1 -1
- package/lib/conninfo.d.ts +2 -2
- package/lib/{context-Bm7rI-oK.d.ts → context-B5Y1lLha.d.ts} +1 -1
- package/lib/context-storage.d.ts +1 -1
- package/lib/{cookie-ClMaKDQf.d.ts → cookie-D9_nQbsM.d.ts} +1 -1
- package/lib/cookie.d.ts +3 -3
- package/lib/cors.d.ts +1 -1
- package/lib/csrf.d.ts +1 -1
- package/lib/dev.d.ts +19 -0
- package/lib/dev.js +50 -0
- package/lib/etag.d.ts +1 -1
- package/lib/factory.d.ts +2 -2
- package/lib/{index-B-3F4wt2.d.ts → index-DtEoak1i.d.ts} +2 -2
- package/lib/{index-UTBmM3GX.d.ts → index-Kqou8Fjh.d.ts} +2 -2
- package/lib/{index-oOClm_Xk.d.ts → index-m12zcmph.d.ts} +3 -3
- package/lib/index.d.ts +4 -4
- package/lib/ip-restriction.d.ts +2 -2
- package/lib/jwk.d.ts +4 -4
- package/lib/{jwt-Dg493Tai.d.ts → jwt-BA65QhnJ.d.ts} +1 -1
- package/lib/jwt.d.ts +4 -4
- package/lib/language.d.ts +1 -1
- package/lib/linear-router-C3FPib6h.js +96 -0
- package/lib/logger.d.ts +1 -1
- package/lib/loopback-only.d.ts +1 -1
- package/lib/method-not-allowed.d.ts +2 -2
- package/lib/method-override.d.ts +2 -2
- package/lib/mount.d.ts +44 -0
- package/lib/mount.js +67 -0
- package/lib/node-server/conninfo.d.ts +1 -1
- package/lib/node-server/serve-static.d.ts +1 -1
- package/lib/node-server.d.ts +1 -1
- package/lib/pattern-router-HZxjDGEQ.js +41 -0
- package/lib/powered-by.d.ts +1 -1
- package/lib/pretty-json.d.ts +1 -1
- package/lib/proxy.d.ts +72 -0
- package/lib/proxy.js +121 -0
- package/lib/quick.d.ts +8 -0
- package/lib/quick.js +17 -0
- package/lib/request-id.d.ts +1 -1
- package/lib/request.d.ts +1 -1
- package/lib/route.d.ts +1 -1
- package/lib/router/linear-router.js +1 -95
- package/lib/router/pattern-router.js +1 -40
- package/lib/schema-validator.d.ts +1 -1
- package/lib/secure-headers.d.ts +1 -1
- package/lib/serve-static.d.ts +1 -1
- package/lib/streaming.d.ts +1 -1
- package/lib/testing.d.ts +4 -4
- package/lib/timeout.d.ts +1 -1
- package/lib/timing.d.ts +1 -1
- package/lib/tiny.d.ts +8 -0
- package/lib/tiny.js +15 -0
- package/lib/trailing-slash.d.ts +1 -1
- package/lib/{types-CHesD1KG.d.ts → types-Bd29gh2o.d.ts} +3 -3
- package/lib/{types-CwrQjlaM.d.ts → types-D9DEXMjE.d.ts} +3 -1
- package/lib/{types-CDO6I3B0.d.ts → types-ZM9gIiKh.d.ts} +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/utils/body.d.ts +1 -1
- package/lib/utils/cookie.d.ts +1 -1
- package/lib/utils/crypto.d.ts +1 -1
- package/lib/utils/ipaddr.d.ts +1 -1
- package/lib/utils/jwt.d.ts +1 -1
- package/lib/utils/types.d.ts +2 -2
- package/lib/validator.d.ts +2 -2
- package/lib/ws.d.ts +1 -1
- package/package.json +25 -1
- package/plugins/acryl-inspect/upstream.json +1 -1
- package/plugins/acryl-node-server/upstream.json +1 -1
- package/plugins/acryl-router/src/core/helper/dev/index.test.ts +181 -0
- package/plugins/acryl-router/src/core/helper/dev/index.ts +79 -0
- package/plugins/acryl-router/src/core/helper/proxy/index.test.ts +356 -0
- package/plugins/acryl-router/src/core/helper/proxy/index.ts +203 -0
- package/plugins/acryl-router/src/core/middleware/cache/index.test.ts +1211 -0
- package/plugins/acryl-router/src/core/middleware/cache/index.ts +323 -0
- package/plugins/acryl-router/src/core/middleware/mount/index.test.ts +334 -0
- package/plugins/acryl-router/src/core/middleware/mount/index.ts +108 -0
- package/plugins/acryl-router/src/core/preset/quick.test.ts +42 -0
- package/plugins/acryl-router/src/core/preset/quick.ts +24 -0
- package/plugins/acryl-router/src/core/preset/tiny.test.ts +42 -0
- package/plugins/acryl-router/src/core/preset/tiny.ts +20 -0
- package/plugins/acryl-router/src/core/utils/types.ts +3 -0
- package/plugins/acryl-router/src/helpers/index.ts +2 -0
- package/plugins/acryl-router/src/middleware/index.ts +2 -0
- package/plugins/acryl-router/src/service.ts +22 -5
- package/plugins/acryl-router/upstream.json +2 -2
- package/plugins/acryl-router-http/upstream.json +1 -1
- package/plugins/acryl-state/upstream.json +1 -1
- package/plugins/desktop/upstream.json +1 -1
- package/plugins/desktop-web/main.ts +92 -0
- package/plugins/desktop-web/plugin.json +17 -0
- package/plugins/desktop-web/shutdown.ts +177 -0
- package/plugins/desktop-web/upstream.json +12 -0
- package/plugins/desktop-web/user-data.ts +38 -0
- package/plugins/desktop-web/window.ts +29 -0
- package/plugins/tsconfig.json +2 -0
- package/templates/todo/upstream.json +1 -1
package/lib/mount.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/middleware/mount/index.d.ts
|
|
4
|
+
type ApplicationHandler = (request: Request, ...args: any) => Response | Promise<Response>;
|
|
5
|
+
type MountOptionHandler = (c: Context) => unknown;
|
|
6
|
+
type MountReplaceRequest = (originalRequest: Request) => Request;
|
|
7
|
+
type MountOptions = MountOptionHandler | {
|
|
8
|
+
optionHandler?: MountOptionHandler;
|
|
9
|
+
replaceRequest?: MountReplaceRequest | false;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* `mount()` allows you to mount applications built with other frameworks into your Acryl application.
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
* @param {Function} applicationHandler - other Request Handler
|
|
16
|
+
* @param {MountOptions} [options] - options of `mount()`
|
|
17
|
+
* @returns {MiddlewareHandler} handler to register with `app.all()`
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { Router as IttyRouter } from 'itty-router'
|
|
22
|
+
* import { Acryl } from 'acrylblends'
|
|
23
|
+
* import { mount } from 'acrylblends/mount'
|
|
24
|
+
* // Create itty-router application
|
|
25
|
+
* const ittyRouter = IttyRouter()
|
|
26
|
+
* // GET /itty-router/hello
|
|
27
|
+
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
28
|
+
*
|
|
29
|
+
* const app = new Acryl()
|
|
30
|
+
* app.all('/itty-router/*', mount(ittyRouter.handle))
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const app = new Acryl()
|
|
36
|
+
* // Send the request to another application without modification.
|
|
37
|
+
* app.all('/app/*', mount(anotherApp, {
|
|
38
|
+
* replaceRequest: (req) => req,
|
|
39
|
+
* }))
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare const mount: (applicationHandler: ApplicationHandler, options?: MountOptions) => MiddlewareHandler;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { type ApplicationHandler, type MountOptionHandler, type MountOptions, type MountReplaceRequest, mount };
|
package/lib/mount.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { routePath } from "./route.js";
|
|
2
|
+
//#region ../../plugins/acryl-router/src/core/middleware/mount/index.ts
|
|
3
|
+
const defaultReplaceRequest = (c) => {
|
|
4
|
+
const pathPrefix = routePath(c).replace(/\/\*$/, "");
|
|
5
|
+
const url = new URL(c.req.raw.url);
|
|
6
|
+
url.pathname = c.req.path.slice(pathPrefix.length) || "/";
|
|
7
|
+
return new Request(url, c.req.raw);
|
|
8
|
+
};
|
|
9
|
+
const defaultGetOptions = (c) => {
|
|
10
|
+
let executionContext = void 0;
|
|
11
|
+
try {
|
|
12
|
+
executionContext = c.executionCtx;
|
|
13
|
+
} catch {}
|
|
14
|
+
return [c.env, executionContext];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* `mount()` allows you to mount applications built with other frameworks into your Acryl application.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* @param {Function} applicationHandler - other Request Handler
|
|
21
|
+
* @param {MountOptions} [options] - options of `mount()`
|
|
22
|
+
* @returns {MiddlewareHandler} handler to register with `app.all()`
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { Router as IttyRouter } from 'itty-router'
|
|
27
|
+
* import { Acryl } from 'acrylblends'
|
|
28
|
+
* import { mount } from 'acrylblends/mount'
|
|
29
|
+
* // Create itty-router application
|
|
30
|
+
* const ittyRouter = IttyRouter()
|
|
31
|
+
* // GET /itty-router/hello
|
|
32
|
+
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
33
|
+
*
|
|
34
|
+
* const app = new Acryl()
|
|
35
|
+
* app.all('/itty-router/*', mount(ittyRouter.handle))
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const app = new Acryl()
|
|
41
|
+
* // Send the request to another application without modification.
|
|
42
|
+
* app.all('/app/*', mount(anotherApp, {
|
|
43
|
+
* replaceRequest: (req) => req,
|
|
44
|
+
* }))
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
const mount = (applicationHandler, options) => {
|
|
48
|
+
let replaceRequest;
|
|
49
|
+
let optionHandler;
|
|
50
|
+
if (options) if (typeof options === "function") optionHandler = options;
|
|
51
|
+
else {
|
|
52
|
+
optionHandler = options.optionHandler;
|
|
53
|
+
if (options.replaceRequest === false) replaceRequest = (request) => request;
|
|
54
|
+
else replaceRequest = options.replaceRequest;
|
|
55
|
+
}
|
|
56
|
+
const getOptions = optionHandler ? (c) => {
|
|
57
|
+
const options = optionHandler(c);
|
|
58
|
+
return Array.isArray(options) ? options : [options];
|
|
59
|
+
} : defaultGetOptions;
|
|
60
|
+
return async (c, next) => {
|
|
61
|
+
const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
|
|
62
|
+
if (res) return res;
|
|
63
|
+
await next();
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { mount };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, _ as Env, t as Context } from "../context-
|
|
1
|
+
import { I as MiddlewareHandler, _ as Env, t as Context } from "../context-B5Y1lLha.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-node-server/src/adapter/serve-static.d.ts
|
|
4
4
|
type ServeStaticOptions<E extends Env = Env> = {
|
package/lib/node-server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as UpgradeWebSocket } from "./index-
|
|
1
|
+
import { n as UpgradeWebSocket } from "./index-Kqou8Fjh.js";
|
|
2
2
|
import { ServeStaticOptions, serveStatic } from "./node-server/serve-static.js";
|
|
3
3
|
import { getConnInfo } from "./node-server/conninfo.js";
|
|
4
4
|
import { AddressInfo } from "node:net";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { UnsupportedPathError } from "./router.js";
|
|
2
|
+
//#region ../../plugins/acryl-router/src/core/router/pattern-router/router.ts
|
|
3
|
+
const emptyParams = Object.create(null);
|
|
4
|
+
var PatternRouter = class {
|
|
5
|
+
name = "PatternRouter";
|
|
6
|
+
#routes = [];
|
|
7
|
+
add(method, path, handler) {
|
|
8
|
+
const suffix = path.endsWith("/*") ? "(?:$|/)" : path.endsWith("*") ? "" : "/?$";
|
|
9
|
+
path = path.replace(/\*$/, "");
|
|
10
|
+
if (path.at(-1) === "?") {
|
|
11
|
+
path = path.slice(0, -1);
|
|
12
|
+
this.add(method, path.replace(/\/[^/]+$/, ""), handler);
|
|
13
|
+
}
|
|
14
|
+
const parts = (path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+/g) || []).map((part) => {
|
|
15
|
+
const match = part.match(/^\/:([^{]+)(?:{(.*)})?/);
|
|
16
|
+
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.replace(/[.\\+*[^\]$()]/g, "\\$&");
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
this.#routes.push([
|
|
20
|
+
new RegExp(`^${parts.join("")}${suffix}`),
|
|
21
|
+
method,
|
|
22
|
+
handler
|
|
23
|
+
]);
|
|
24
|
+
} catch {
|
|
25
|
+
throw new UnsupportedPathError();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
match(method, path) {
|
|
29
|
+
const handlers = [];
|
|
30
|
+
for (let i = 0, len = this.#routes.length; i < len; i++) {
|
|
31
|
+
const [pattern, routeMethod, handler] = this.#routes[i];
|
|
32
|
+
if (routeMethod === method || routeMethod === "ALL") {
|
|
33
|
+
const match = pattern.exec(path);
|
|
34
|
+
if (match) handlers.push([handler, match.groups || emptyParams]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return [handlers];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { PatternRouter as t };
|
package/lib/powered-by.d.ts
CHANGED
package/lib/pretty-json.d.ts
CHANGED
package/lib/proxy.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { r as RequestHeader } from "./headers-tu2YYN8T.js";
|
|
2
|
+
import { c as HeadersInit } from "./types-D9DEXMjE.js";
|
|
3
|
+
|
|
4
|
+
//#region ../../plugins/acryl-router/src/core/helper/proxy/index.d.ts
|
|
5
|
+
interface ProxyRequestInit extends Omit<RequestInit, 'headers'> {
|
|
6
|
+
raw?: Request;
|
|
7
|
+
headers?: HeadersInit | [string, string][] | Record<RequestHeader, string | undefined> | Record<string, string | undefined>;
|
|
8
|
+
customFetch?: (request: Request) => Promise<Response>;
|
|
9
|
+
/**
|
|
10
|
+
* Enable strict RFC 9110 compliance for Connection header processing.
|
|
11
|
+
*
|
|
12
|
+
* - `false` (default): Ignores Connection header to prevent potential
|
|
13
|
+
* Hop-by-Hop Header Injection attacks. Recommended for untrusted clients.
|
|
14
|
+
* - `true`: Processes Connection header per RFC 9110 and removes listed headers.
|
|
15
|
+
* Only use in trusted environments.
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
* @see https://datatracker.ietf.org/doc/html/rfc9110#section-7.6.1
|
|
19
|
+
*/
|
|
20
|
+
strictConnectionProcessing?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface ProxyFetch {
|
|
23
|
+
(input: string | URL | Request, init?: ProxyRequestInit): Promise<Response>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Fetch API wrapper for proxy.
|
|
27
|
+
* The parameters and return value are the same as for `fetch` (except for the proxy-specific options).
|
|
28
|
+
*
|
|
29
|
+
* The "Accept-Encoding" header is replaced with an encoding that the current runtime can handle.
|
|
30
|
+
* Unnecessary response headers are deleted and a Response object is returned that can be returned
|
|
31
|
+
* as is as a response from the handler.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* app.get('/proxy/:path', (c) => {
|
|
36
|
+
* return proxy(`http://${originServer}/${c.req.param('path')}`, {
|
|
37
|
+
* headers: {
|
|
38
|
+
* ...c.req.header(), // optional, specify only when forwarding all the request data (including credentials) is necessary.
|
|
39
|
+
* 'X-Forwarded-For': '127.0.0.1',
|
|
40
|
+
* 'X-Forwarded-Host': c.req.header('host'),
|
|
41
|
+
* Authorization: undefined, // do not propagate request headers contained in c.req.header('Authorization')
|
|
42
|
+
* },
|
|
43
|
+
* }).then((res) => {
|
|
44
|
+
* res.headers.delete('Set-Cookie')
|
|
45
|
+
* return res
|
|
46
|
+
* })
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
49
|
+
* app.all('/proxy/:path', (c) => {
|
|
50
|
+
* return proxy(`http://${originServer}/${c.req.param('path')}`, {
|
|
51
|
+
* ...c.req, // optional, specify only when forwarding all the request data (including credentials) is necessary.
|
|
52
|
+
* headers: {
|
|
53
|
+
* ...c.req.header(),
|
|
54
|
+
* 'X-Forwarded-For': '127.0.0.1',
|
|
55
|
+
* 'X-Forwarded-Host': c.req.header('host'),
|
|
56
|
+
* Authorization: undefined, // do not propagate request headers contained in c.req.header('Authorization')
|
|
57
|
+
* },
|
|
58
|
+
* })
|
|
59
|
+
* })
|
|
60
|
+
*
|
|
61
|
+
* // Strict RFC compliance mode (use only in trusted environments)
|
|
62
|
+
* app.get('/internal-proxy/:path', (c) => {
|
|
63
|
+
* return proxy(`http://${internalServer}/${c.req.param('path')}`, {
|
|
64
|
+
* ...c.req,
|
|
65
|
+
* strictConnectionProcessing: true,
|
|
66
|
+
* })
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
declare const proxy: ProxyFetch;
|
|
71
|
+
//#endregion
|
|
72
|
+
export { proxy };
|
package/lib/proxy.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { HTTPException } from "./http-exception.js";
|
|
2
|
+
//#region ../../plugins/acryl-router/src/core/helper/proxy/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* @module
|
|
5
|
+
* Proxy Helper for Acryl.
|
|
6
|
+
*/
|
|
7
|
+
const hopByHopHeaders = [
|
|
8
|
+
"connection",
|
|
9
|
+
"keep-alive",
|
|
10
|
+
"proxy-authenticate",
|
|
11
|
+
"proxy-authorization",
|
|
12
|
+
"te",
|
|
13
|
+
"trailer",
|
|
14
|
+
"transfer-encoding",
|
|
15
|
+
"upgrade"
|
|
16
|
+
];
|
|
17
|
+
const ALLOWED_TOKEN_PATTERN = /^[!#$%&'*+\-.0-9A-Z^_`a-z|~]+$/;
|
|
18
|
+
const buildRequestInitFromRequest = (request, strictConnectionProcessing) => {
|
|
19
|
+
if (!request) return {};
|
|
20
|
+
const headers = new Headers(request.headers);
|
|
21
|
+
if (strictConnectionProcessing) {
|
|
22
|
+
const connectionValue = headers.get("connection");
|
|
23
|
+
if (connectionValue) {
|
|
24
|
+
const headerNames = connectionValue.split(",").map((h) => h.trim());
|
|
25
|
+
const invalidHeaders = headerNames.filter((h) => !ALLOWED_TOKEN_PATTERN.test(h));
|
|
26
|
+
if (invalidHeaders.length > 0) throw new HTTPException(400, { message: `Invalid Connection header value: ${invalidHeaders.join(", ")}` });
|
|
27
|
+
headerNames.forEach((headerName) => {
|
|
28
|
+
headers.delete(headerName);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
hopByHopHeaders.forEach((header) => {
|
|
33
|
+
headers.delete(header);
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
method: request.method,
|
|
37
|
+
body: request.body,
|
|
38
|
+
duplex: request.body ? "half" : void 0,
|
|
39
|
+
headers,
|
|
40
|
+
signal: request.signal
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const preprocessRequestInit = (requestInit) => {
|
|
44
|
+
if (!requestInit.headers || Array.isArray(requestInit.headers) || requestInit.headers instanceof Headers) return requestInit;
|
|
45
|
+
const headers = new Headers();
|
|
46
|
+
for (const [key, value] of Object.entries(requestInit.headers)) if (value == null) headers.delete(key);
|
|
47
|
+
else headers.set(key, value);
|
|
48
|
+
requestInit.headers = headers;
|
|
49
|
+
return requestInit;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Fetch API wrapper for proxy.
|
|
53
|
+
* The parameters and return value are the same as for `fetch` (except for the proxy-specific options).
|
|
54
|
+
*
|
|
55
|
+
* The "Accept-Encoding" header is replaced with an encoding that the current runtime can handle.
|
|
56
|
+
* Unnecessary response headers are deleted and a Response object is returned that can be returned
|
|
57
|
+
* as is as a response from the handler.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* app.get('/proxy/:path', (c) => {
|
|
62
|
+
* return proxy(`http://${originServer}/${c.req.param('path')}`, {
|
|
63
|
+
* headers: {
|
|
64
|
+
* ...c.req.header(), // optional, specify only when forwarding all the request data (including credentials) is necessary.
|
|
65
|
+
* 'X-Forwarded-For': '127.0.0.1',
|
|
66
|
+
* 'X-Forwarded-Host': c.req.header('host'),
|
|
67
|
+
* Authorization: undefined, // do not propagate request headers contained in c.req.header('Authorization')
|
|
68
|
+
* },
|
|
69
|
+
* }).then((res) => {
|
|
70
|
+
* res.headers.delete('Set-Cookie')
|
|
71
|
+
* return res
|
|
72
|
+
* })
|
|
73
|
+
* })
|
|
74
|
+
*
|
|
75
|
+
* app.all('/proxy/:path', (c) => {
|
|
76
|
+
* return proxy(`http://${originServer}/${c.req.param('path')}`, {
|
|
77
|
+
* ...c.req, // optional, specify only when forwarding all the request data (including credentials) is necessary.
|
|
78
|
+
* headers: {
|
|
79
|
+
* ...c.req.header(),
|
|
80
|
+
* 'X-Forwarded-For': '127.0.0.1',
|
|
81
|
+
* 'X-Forwarded-Host': c.req.header('host'),
|
|
82
|
+
* Authorization: undefined, // do not propagate request headers contained in c.req.header('Authorization')
|
|
83
|
+
* },
|
|
84
|
+
* })
|
|
85
|
+
* })
|
|
86
|
+
*
|
|
87
|
+
* // Strict RFC compliance mode (use only in trusted environments)
|
|
88
|
+
* app.get('/internal-proxy/:path', (c) => {
|
|
89
|
+
* return proxy(`http://${internalServer}/${c.req.param('path')}`, {
|
|
90
|
+
* ...c.req,
|
|
91
|
+
* strictConnectionProcessing: true,
|
|
92
|
+
* })
|
|
93
|
+
* })
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
const proxy = async (input, proxyInit) => {
|
|
97
|
+
const { raw, customFetch, strictConnectionProcessing = false, ...requestInit } = proxyInit instanceof Request ? { raw: proxyInit } : proxyInit ?? {};
|
|
98
|
+
const req = new Request(input, {
|
|
99
|
+
...buildRequestInitFromRequest(raw, strictConnectionProcessing),
|
|
100
|
+
...preprocessRequestInit(requestInit)
|
|
101
|
+
});
|
|
102
|
+
req.headers.delete("accept-encoding");
|
|
103
|
+
const res = await (customFetch || fetch)(req);
|
|
104
|
+
const resHeaders = new Headers(res.headers);
|
|
105
|
+
const connectionValue = resHeaders.get("connection");
|
|
106
|
+
if (connectionValue) connectionValue.split(",").map((h) => h.trim()).filter((h) => ALLOWED_TOKEN_PATTERN.test(h)).forEach((h) => resHeaders.delete(h));
|
|
107
|
+
hopByHopHeaders.forEach((header) => {
|
|
108
|
+
resHeaders.delete(header);
|
|
109
|
+
});
|
|
110
|
+
if (resHeaders.has("content-encoding")) {
|
|
111
|
+
resHeaders.delete("content-encoding");
|
|
112
|
+
resHeaders.delete("content-length");
|
|
113
|
+
}
|
|
114
|
+
return new Response(res.body, {
|
|
115
|
+
status: res.status,
|
|
116
|
+
statusText: res.statusText,
|
|
117
|
+
headers: resHeaders
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
//#endregion
|
|
121
|
+
export { proxy };
|
package/lib/quick.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { $ as Acryl$1, J as Schema, _ as Env, et as AcrylOptions, h as BlankSchema, p as BlankEnv } from "./context-B5Y1lLha.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/preset/quick.d.ts
|
|
4
|
+
declare class Acryl<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = '/'> extends Acryl$1<E, S, BasePath> {
|
|
5
|
+
constructor(options?: AcrylOptions<E>);
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { Acryl };
|
package/lib/quick.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AcrylBase as Acryl$1 } from "./acryl-base.js";
|
|
2
|
+
import { t as SmartRouter } from "./smart-router-C5CZ5XSM.js";
|
|
3
|
+
import { t as TrieRouter } from "./trie-router-CfFbapzL.js";
|
|
4
|
+
import { t as LinearRouter } from "./linear-router-C3FPib6h.js";
|
|
5
|
+
//#region ../../plugins/acryl-router/src/core/preset/quick.ts
|
|
6
|
+
/**
|
|
7
|
+
* @module
|
|
8
|
+
* The preset that uses `LinearRouter`.
|
|
9
|
+
*/
|
|
10
|
+
var Acryl = class extends Acryl$1 {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
super(options);
|
|
13
|
+
this.router = new SmartRouter({ routers: [new LinearRouter(), new TrieRouter()] });
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { Acryl };
|
package/lib/request-id.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, t as Context } from "./context-
|
|
1
|
+
import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-router/src/core/middleware/request-id/request-id.d.ts
|
|
4
4
|
type RequestIdVariables = {
|
package/lib/request.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { o as AcrylRequest, s as cloneRawRequest } from "./context-
|
|
1
|
+
import { o as AcrylRequest, s as cloneRawRequest } from "./context-B5Y1lLha.js";
|
|
2
2
|
export { AcrylRequest, cloneRawRequest };
|
package/lib/route.d.ts
CHANGED
|
@@ -1,96 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { UnsupportedPathError } from "../router.js";
|
|
3
|
-
//#region ../../plugins/acryl-router/src/core/router/linear-router/router.ts
|
|
4
|
-
const emptyParams = Object.create(null);
|
|
5
|
-
const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
|
|
6
|
-
const splitByStarRe = /\*/;
|
|
7
|
-
var LinearRouter = class {
|
|
8
|
-
name = "LinearRouter";
|
|
9
|
-
#routes = [];
|
|
10
|
-
add(method, path, handler) {
|
|
11
|
-
for (let i = 0, paths = checkOptionalParameter(path) || [path], len = paths.length; i < len; i++) this.#routes.push([
|
|
12
|
-
method,
|
|
13
|
-
paths[i],
|
|
14
|
-
handler
|
|
15
|
-
]);
|
|
16
|
-
}
|
|
17
|
-
match(method, path) {
|
|
18
|
-
const handlers = [];
|
|
19
|
-
ROUTES_LOOP: for (let i = 0, len = this.#routes.length; i < len; i++) {
|
|
20
|
-
const [routeMethod, routePath, handler] = this.#routes[i];
|
|
21
|
-
if (routeMethod === method || routeMethod === "ALL") {
|
|
22
|
-
if (routePath === "*" || routePath === "/*") {
|
|
23
|
-
handlers.push([handler, emptyParams]);
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
const hasStar = routePath.indexOf("*") !== -1;
|
|
27
|
-
const hasLabel = routePath.indexOf(":") !== -1;
|
|
28
|
-
if (!hasStar && !hasLabel) {
|
|
29
|
-
if (routePath === path || routePath + "/" === path) handlers.push([handler, emptyParams]);
|
|
30
|
-
} else if (hasStar && !hasLabel) {
|
|
31
|
-
const endsWithStar = routePath.charCodeAt(routePath.length - 1) === 42;
|
|
32
|
-
const endsWithSlashStar = routePath.endsWith("/*");
|
|
33
|
-
const parts = (endsWithStar ? routePath.slice(0, endsWithSlashStar ? -2 : -1) : routePath).split(splitByStarRe);
|
|
34
|
-
const lastIndex = parts.length - 1;
|
|
35
|
-
for (let j = 0, pos = 0, len = parts.length; j < len; j++) {
|
|
36
|
-
const part = parts[j];
|
|
37
|
-
if (path.indexOf(part, pos) !== pos) continue ROUTES_LOOP;
|
|
38
|
-
pos += part.length;
|
|
39
|
-
if (j === lastIndex) {
|
|
40
|
-
if (endsWithSlashStar) {
|
|
41
|
-
if (pos !== path.length && path.charCodeAt(pos) !== 47) continue ROUTES_LOOP;
|
|
42
|
-
} else if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) continue ROUTES_LOOP;
|
|
43
|
-
} else {
|
|
44
|
-
const index = path.indexOf("/", pos);
|
|
45
|
-
if (index === -1) continue ROUTES_LOOP;
|
|
46
|
-
pos = index;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
handlers.push([handler, emptyParams]);
|
|
50
|
-
} else if (hasLabel && !hasStar) {
|
|
51
|
-
const params = Object.create(null);
|
|
52
|
-
const parts = routePath.match(splitPathRe);
|
|
53
|
-
const lastIndex = parts.length - 1;
|
|
54
|
-
for (let j = 0, pos = 0, len = parts.length; j < len; j++) {
|
|
55
|
-
if (pos === -1 || pos >= path.length) continue ROUTES_LOOP;
|
|
56
|
-
const part = parts[j];
|
|
57
|
-
if (part.charCodeAt(1) === 58) {
|
|
58
|
-
if (path.charCodeAt(pos) !== 47) continue ROUTES_LOOP;
|
|
59
|
-
let name = part.slice(2);
|
|
60
|
-
let value;
|
|
61
|
-
if (name.charCodeAt(name.length - 1) === 125) {
|
|
62
|
-
const openBracePos = name.indexOf("{");
|
|
63
|
-
const next = parts[j + 1];
|
|
64
|
-
const lookahead = next && next[1] !== ":" && next[1] !== "*" ? `(?=${next})` : "";
|
|
65
|
-
const pattern = name.slice(openBracePos + 1, -1) + lookahead;
|
|
66
|
-
const restPath = path.slice(pos + 1);
|
|
67
|
-
const match = new RegExp(pattern, "d").exec(restPath);
|
|
68
|
-
if (!match || match.indices[0][0] !== 0 || match.indices[0][1] === 0) continue ROUTES_LOOP;
|
|
69
|
-
name = name.slice(0, openBracePos);
|
|
70
|
-
value = restPath.slice(...match.indices[0]);
|
|
71
|
-
pos += match.indices[0][1] + 1;
|
|
72
|
-
} else {
|
|
73
|
-
let endValuePos = path.indexOf("/", pos + 1);
|
|
74
|
-
if (endValuePos === -1) endValuePos = path.length;
|
|
75
|
-
if (endValuePos === pos + 1) continue ROUTES_LOOP;
|
|
76
|
-
value = path.slice(pos + 1, endValuePos);
|
|
77
|
-
pos = endValuePos;
|
|
78
|
-
}
|
|
79
|
-
params[name] ||= value;
|
|
80
|
-
} else {
|
|
81
|
-
if (path.indexOf(part, pos) !== pos) continue ROUTES_LOOP;
|
|
82
|
-
pos += part.length;
|
|
83
|
-
}
|
|
84
|
-
if (j === lastIndex) {
|
|
85
|
-
if (pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) continue ROUTES_LOOP;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
handlers.push([handler, params]);
|
|
89
|
-
} else if (hasLabel && hasStar) throw new UnsupportedPathError();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return [handlers];
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
//#endregion
|
|
1
|
+
import { t as LinearRouter } from "../linear-router-C3FPib6h.js";
|
|
96
2
|
export { LinearRouter };
|
|
@@ -1,41 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region ../../plugins/acryl-router/src/core/router/pattern-router/router.ts
|
|
3
|
-
const emptyParams = Object.create(null);
|
|
4
|
-
var PatternRouter = class {
|
|
5
|
-
name = "PatternRouter";
|
|
6
|
-
#routes = [];
|
|
7
|
-
add(method, path, handler) {
|
|
8
|
-
const suffix = path.endsWith("/*") ? "(?:$|/)" : path.endsWith("*") ? "" : "/?$";
|
|
9
|
-
path = path.replace(/\*$/, "");
|
|
10
|
-
if (path.at(-1) === "?") {
|
|
11
|
-
path = path.slice(0, -1);
|
|
12
|
-
this.add(method, path.replace(/\/[^/]+$/, ""), handler);
|
|
13
|
-
}
|
|
14
|
-
const parts = (path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+/g) || []).map((part) => {
|
|
15
|
-
const match = part.match(/^\/:([^{]+)(?:{(.*)})?/);
|
|
16
|
-
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.replace(/[.\\+*[^\]$()]/g, "\\$&");
|
|
17
|
-
});
|
|
18
|
-
try {
|
|
19
|
-
this.#routes.push([
|
|
20
|
-
new RegExp(`^${parts.join("")}${suffix}`),
|
|
21
|
-
method,
|
|
22
|
-
handler
|
|
23
|
-
]);
|
|
24
|
-
} catch {
|
|
25
|
-
throw new UnsupportedPathError();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
match(method, path) {
|
|
29
|
-
const handlers = [];
|
|
30
|
-
for (let i = 0, len = this.#routes.length; i < len; i++) {
|
|
31
|
-
const [pattern, routeMethod, handler] = this.#routes[i];
|
|
32
|
-
if (routeMethod === method || routeMethod === "ALL") {
|
|
33
|
-
const match = pattern.exec(path);
|
|
34
|
-
if (match) handlers.push([handler, match.groups || emptyParams]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return [handlers];
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
//#endregion
|
|
1
|
+
import { t as PatternRouter } from "../pattern-router-HZxjDGEQ.js";
|
|
41
2
|
export { PatternRouter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, Z as ValidationTargets, _ as Env } from "./context-
|
|
1
|
+
import { I as MiddlewareHandler, Z as ValidationTargets, _ as Env } from "./context-B5Y1lLha.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-router/src/helpers/schema-validator.d.ts
|
|
4
4
|
/** The slice of the Standard Schema interface this needs; Schemastery (what Cordis uses), Zod and Valibot all implement it. */
|
package/lib/secure-headers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, t as Context } from "./context-
|
|
1
|
+
import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-router/src/core/middleware/secure-headers/permissions-policy.d.ts
|
|
4
4
|
type PermissionsPolicyDirective = StandardizedFeatures | ProposedFeatures | ExperimentalFeatures;
|
package/lib/serve-static.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, _ as Env, i as Data, t as Context } from "./context-
|
|
1
|
+
import { I as MiddlewareHandler, _ as Env, i as Data, t as Context } from "./context-B5Y1lLha.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-router/src/core/middleware/serve-static/index.d.ts
|
|
4
4
|
type ServeStaticOptions<E extends Env = Env> = {
|
package/lib/streaming.d.ts
CHANGED
package/lib/testing.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { J as Schema, a as ExecutionContext } from "./context-
|
|
2
|
-
import {
|
|
3
|
-
import { t as Acryl } from "./app-
|
|
4
|
-
import { i as ClientRequestOptions, n as Client } from "./types-
|
|
1
|
+
import { J as Schema, a as ExecutionContext } from "./context-B5Y1lLha.js";
|
|
2
|
+
import { E as UnionToIntersection } from "./types-D9DEXMjE.js";
|
|
3
|
+
import { t as Acryl } from "./app-BdrVHBlJ.js";
|
|
4
|
+
import { i as ClientRequestOptions, n as Client } from "./types-Bd29gh2o.js";
|
|
5
5
|
|
|
6
6
|
//#region ../../plugins/acryl-router/src/core/helper/testing/index.d.ts
|
|
7
7
|
type ExtractEnv<T> = T extends Acryl<infer E, Schema, string> ? E : never;
|
package/lib/timeout.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, t as Context } from "./context-
|
|
1
|
+
import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
|
|
2
2
|
import { HTTPException } from "./http-exception.js";
|
|
3
3
|
|
|
4
4
|
//#region ../../plugins/acryl-router/src/core/middleware/timeout/index.d.ts
|
package/lib/timing.d.ts
CHANGED
package/lib/tiny.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { $ as Acryl$1, J as Schema, _ as Env, et as AcrylOptions, h as BlankSchema, p as BlankEnv } from "./context-B5Y1lLha.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/preset/tiny.d.ts
|
|
4
|
+
declare class Acryl<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = '/'> extends Acryl$1<E, S, BasePath> {
|
|
5
|
+
constructor(options?: AcrylOptions<E>);
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { Acryl };
|
package/lib/tiny.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AcrylBase as Acryl$1 } from "./acryl-base.js";
|
|
2
|
+
import { t as PatternRouter } from "./pattern-router-HZxjDGEQ.js";
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/preset/tiny.ts
|
|
4
|
+
/**
|
|
5
|
+
* @module
|
|
6
|
+
* The preset that uses `PatternRouter`.
|
|
7
|
+
*/
|
|
8
|
+
var Acryl = class extends Acryl$1 {
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
super(options);
|
|
11
|
+
this.router = new PatternRouter();
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { Acryl };
|