acrylblends 0.7.3 → 0.7.4
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/docs/framework/README.md +4 -3
- package/docs/framework/UPSTREAM.md +1 -1
- package/docs/framework/getting-started/aws-lambda.md +115 -0
- package/docs/framework/getting-started/bun.md +1 -3
- package/docs/framework/getting-started/cloudflare-pages.md +53 -0
- package/docs/framework/getting-started/cloudflare-workers.md +67 -0
- package/docs/framework/getting-started/lambda-edge.md +41 -0
- package/docs/framework/getting-started/netlify.md +25 -0
- package/docs/framework/getting-started/other-runtimes.md +20 -9
- package/docs/framework/getting-started/service-worker.md +31 -0
- package/docs/framework/getting-started/vercel.md +28 -0
- package/docs/framework/guides/create-acrylblends.md +40 -2
- package/docs/framework/guides/faq.md +2 -2
- package/docs/framework/helpers/conninfo.md +1 -1
- package/docs/framework/helpers/ssg.md +1 -1
- package/docs/framework/helpers/streaming.md +3 -2
- package/docs/framework/helpers/websocket.md +2 -2
- package/docs/framework/middleware/builtin/ip-restriction.md +1 -1
- package/docs/framework/upstream.json +3 -3
- package/lib/aws-lambda.d.ts +324 -0
- package/lib/aws-lambda.js +357 -0
- package/lib/bun.d.ts +75 -0
- package/lib/bun.js +134 -0
- package/lib/cloudflare-pages.d.ts +58 -0
- package/lib/cloudflare-pages.js +78 -0
- package/lib/cloudflare-workers.d.ts +21 -0
- package/lib/cloudflare-workers.js +80 -0
- package/lib/index-CseujaYI.d.ts +31 -0
- package/lib/index-DaJtL7ci.d.ts +156 -0
- package/lib/lambda-edge.d.ts +92 -0
- package/lib/lambda-edge.js +105 -0
- package/lib/netlify.d.ts +29 -0
- package/lib/netlify.js +30 -0
- package/lib/node-server/register.js +1 -1
- package/lib/node-server/serve-static.js +1 -1
- package/lib/node-server.js +3 -3
- package/lib/serve-static-Cp5adzGo.js +77 -0
- package/lib/serve-static.d.ts +1 -30
- package/lib/serve-static.js +1 -76
- package/lib/service-worker.d.ts +48 -0
- package/lib/service-worker.js +38 -0
- package/lib/ssg.d.ts +1 -155
- package/lib/vercel.d.ts +10 -0
- package/lib/vercel.js +9 -0
- package/package.json +33 -1
- package/plugins/acryl-inspect/upstream.json +1 -1
- package/plugins/acryl-node-server/upstream.json +1 -1
- package/plugins/acryl-router/src/core/adapter/aws-lambda/conninfo.ts +73 -0
- package/plugins/acryl-router/src/core/adapter/aws-lambda/handler.ts +682 -0
- package/plugins/acryl-router/src/core/adapter/aws-lambda/index.ts +14 -0
- package/plugins/acryl-router/src/core/adapter/aws-lambda/types.ts +173 -0
- package/plugins/acryl-router/src/core/adapter/bun/conninfo.ts +43 -0
- package/plugins/acryl-router/src/core/adapter/bun/index.ts +11 -0
- package/plugins/acryl-router/src/core/adapter/bun/serve-static.ts +32 -0
- package/plugins/acryl-router/src/core/adapter/bun/server.ts +14 -0
- package/plugins/acryl-router/src/core/adapter/bun/ssg.ts +26 -0
- package/plugins/acryl-router/src/core/adapter/bun/websocket.ts +113 -0
- package/plugins/acryl-router/src/core/adapter/cloudflare-pages/conninfo.ts +26 -0
- package/plugins/acryl-router/src/core/adapter/cloudflare-pages/handler.ts +122 -0
- package/plugins/acryl-router/src/core/adapter/cloudflare-pages/index.ts +11 -0
- package/plugins/acryl-router/src/core/adapter/cloudflare-workers/conninfo.ts +7 -0
- package/plugins/acryl-router/src/core/adapter/cloudflare-workers/index.ts +8 -0
- package/plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static-module.ts +12 -0
- package/plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static.ts +41 -0
- package/plugins/acryl-router/src/core/adapter/cloudflare-workers/utils.ts +50 -0
- package/plugins/acryl-router/src/core/adapter/cloudflare-workers/websocket.ts +52 -0
- package/plugins/acryl-router/src/core/adapter/lambda-edge/conninfo.ts +15 -0
- package/plugins/acryl-router/src/core/adapter/lambda-edge/handler.ts +239 -0
- package/plugins/acryl-router/src/core/adapter/lambda-edge/index.ts +14 -0
- package/plugins/acryl-router/src/core/adapter/netlify/conninfo.ts +57 -0
- package/plugins/acryl-router/src/core/adapter/netlify/handler.ts +10 -0
- package/plugins/acryl-router/src/core/adapter/netlify/index.ts +6 -0
- package/plugins/acryl-router/src/core/adapter/netlify/mod.ts +2 -0
- package/plugins/acryl-router/src/core/adapter/service-worker/handler.ts +37 -0
- package/plugins/acryl-router/src/core/adapter/service-worker/index.ts +36 -0
- package/plugins/acryl-router/src/core/adapter/service-worker/types.ts +14 -0
- package/plugins/acryl-router/src/core/adapter/vercel/conninfo.ts +8 -0
- package/plugins/acryl-router/src/core/adapter/vercel/handler.ts +8 -0
- package/plugins/acryl-router/src/core/adapter/vercel/index.ts +7 -0
- 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/upstream.json +1 -1
- package/templates/todo/upstream.json +1 -1
- package/lib/{serve-static-B14MF1Va.js → serve-static-B849HlX2.js} +1 -1
- package/lib/{transpile-CTnWof4z.js → transpile-QUK9b3eG.js} +1 -1
package/lib/bun.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { L as MiddlewareHandler, t as Context, v as Env } from "./context-DS3fYyG-.js";
|
|
2
|
+
import { r as GetConnInfo } from "./types-Dv_nV2cv.js";
|
|
3
|
+
import { f as FileSystemModule, m as ToSSGAdaptorInterface } from "./index-DaJtL7ci.js";
|
|
4
|
+
import { a as WSEvents, n as UpgradeWebSocket } from "./index-BvFh1Gfx.js";
|
|
5
|
+
import { t as ServeStaticOptions } from "./index-CseujaYI.js";
|
|
6
|
+
|
|
7
|
+
//#region ../../plugins/acryl-router/src/core/adapter/bun/serve-static.d.ts
|
|
8
|
+
declare const serveStatic: <E extends Env = Env>(options?: ServeStaticOptions<E>) => MiddlewareHandler;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region ../../plugins/acryl-router/src/core/adapter/bun/ssg.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* @experimental
|
|
13
|
+
* `bunFileSystemModule` is an experimental feature.
|
|
14
|
+
* The API might be changed.
|
|
15
|
+
*/
|
|
16
|
+
declare const bunFileSystemModule: FileSystemModule;
|
|
17
|
+
/**
|
|
18
|
+
* @experimental
|
|
19
|
+
* `toSSG` is an experimental feature.
|
|
20
|
+
* The API might be changed.
|
|
21
|
+
*/
|
|
22
|
+
declare const toSSG: ToSSGAdaptorInterface;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region ../../plugins/acryl-router/src/core/adapter/bun/websocket.d.ts
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
interface BunServerWebSocket<T> {
|
|
29
|
+
send(data: string | ArrayBuffer | Uint8Array, compress?: boolean): void;
|
|
30
|
+
close(code?: number, reason?: string): void;
|
|
31
|
+
data: T;
|
|
32
|
+
readyState: 0 | 1 | 2 | 3;
|
|
33
|
+
}
|
|
34
|
+
interface BunWebSocketHandler<T> {
|
|
35
|
+
open(ws: BunServerWebSocket<T>): void;
|
|
36
|
+
close(ws: BunServerWebSocket<T>, code?: number, reason?: string): void;
|
|
37
|
+
message(ws: BunServerWebSocket<T>, message: string | {
|
|
38
|
+
buffer: ArrayBufferLike;
|
|
39
|
+
}): void;
|
|
40
|
+
}
|
|
41
|
+
interface CreateWebSocket<T> {
|
|
42
|
+
upgradeWebSocket: UpgradeWebSocket<T>;
|
|
43
|
+
websocket: BunWebSocketHandler<BunWebSocketData>;
|
|
44
|
+
}
|
|
45
|
+
interface BunWebSocketData {
|
|
46
|
+
events: WSEvents;
|
|
47
|
+
url: URL;
|
|
48
|
+
protocol: string;
|
|
49
|
+
}
|
|
50
|
+
declare const upgradeWebSocket: UpgradeWebSocket<any>;
|
|
51
|
+
declare const websocket: BunWebSocketHandler<BunWebSocketData>;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Import `upgradeWebSocket` and `websocket` directly from `acryl-router/bun` instead.
|
|
54
|
+
* @returns A function to create a Bun WebSocket handler.
|
|
55
|
+
*/
|
|
56
|
+
declare const createBunWebSocket: <T>() => CreateWebSocket<T>;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region ../../plugins/acryl-router/src/core/adapter/bun/conninfo.d.ts
|
|
59
|
+
/**
|
|
60
|
+
* Get ConnInfo with Bun
|
|
61
|
+
* @param c Context
|
|
62
|
+
* @returns ConnInfo
|
|
63
|
+
*/
|
|
64
|
+
declare const getConnInfo: GetConnInfo;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region ../../plugins/acryl-router/src/core/adapter/bun/server.d.ts
|
|
67
|
+
/**
|
|
68
|
+
* Get Bun Server Object from Context
|
|
69
|
+
* @template T - The type of Bun Server
|
|
70
|
+
* @param c Context
|
|
71
|
+
* @returns Bun Server
|
|
72
|
+
*/
|
|
73
|
+
declare const getBunServer: <T>(c: Context) => T | undefined;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { type BunWebSocketData, type BunWebSocketHandler, bunFileSystemModule, createBunWebSocket, getBunServer, getConnInfo, serveStatic, toSSG, upgradeWebSocket, websocket };
|
package/lib/bun.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { t as serveStatic$1 } from "./serve-static-Cp5adzGo.js";
|
|
2
|
+
import { c as toSSG$1 } from "./ssg-BwjcA-Ge.js";
|
|
3
|
+
import { WSContext, createWSMessageEvent, defineWebSocketHelper } from "./ws.js";
|
|
4
|
+
import { stat } from "node:fs/promises";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
//#region ../../plugins/acryl-router/src/core/adapter/bun/serve-static.ts
|
|
7
|
+
const serveStatic = (options = {}) => {
|
|
8
|
+
return async function serveStatic(c, next) {
|
|
9
|
+
const getContent = async (path) => {
|
|
10
|
+
const file = Bun.file(path);
|
|
11
|
+
return await file.exists() ? file : null;
|
|
12
|
+
};
|
|
13
|
+
const isDir = async (path) => {
|
|
14
|
+
let isDir;
|
|
15
|
+
try {
|
|
16
|
+
isDir = (await stat(path)).isDirectory();
|
|
17
|
+
} catch {}
|
|
18
|
+
return isDir;
|
|
19
|
+
};
|
|
20
|
+
return serveStatic$1({
|
|
21
|
+
...options,
|
|
22
|
+
getContent,
|
|
23
|
+
join,
|
|
24
|
+
isDir
|
|
25
|
+
})(c, next);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region ../../plugins/acryl-router/src/core/adapter/bun/ssg.ts
|
|
30
|
+
/**
|
|
31
|
+
* @experimental
|
|
32
|
+
* `bunFileSystemModule` is an experimental feature.
|
|
33
|
+
* The API might be changed.
|
|
34
|
+
*/
|
|
35
|
+
const bunFileSystemModule = {
|
|
36
|
+
writeFile: async (path, data) => {
|
|
37
|
+
await Bun.write(path, data);
|
|
38
|
+
},
|
|
39
|
+
mkdir: async () => {}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* @experimental
|
|
43
|
+
* `toSSG` is an experimental feature.
|
|
44
|
+
* The API might be changed.
|
|
45
|
+
*/
|
|
46
|
+
const toSSG = async (app, options) => {
|
|
47
|
+
return toSSG$1(app, bunFileSystemModule, options);
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region ../../plugins/acryl-router/src/core/adapter/bun/server.ts
|
|
51
|
+
/**
|
|
52
|
+
* Get Bun Server Object from Context
|
|
53
|
+
* @template T - The type of Bun Server
|
|
54
|
+
* @param c Context
|
|
55
|
+
* @returns Bun Server
|
|
56
|
+
*/
|
|
57
|
+
const getBunServer = (c) => "server" in c.env ? c.env.server : c.env;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region ../../plugins/acryl-router/src/core/adapter/bun/websocket.ts
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
const createWSContext = (ws) => {
|
|
64
|
+
return new WSContext({
|
|
65
|
+
send: (source, options) => {
|
|
66
|
+
ws.send(source, options?.compress);
|
|
67
|
+
},
|
|
68
|
+
raw: ws,
|
|
69
|
+
readyState: ws.readyState,
|
|
70
|
+
url: ws.data.url,
|
|
71
|
+
protocol: ws.data.protocol,
|
|
72
|
+
close(code, reason) {
|
|
73
|
+
ws.close(code, reason);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const upgradeWebSocket = defineWebSocketHelper((c, events) => {
|
|
78
|
+
const server = getBunServer(c);
|
|
79
|
+
if (!server) throw new TypeError("env has to include the 2nd argument of fetch.");
|
|
80
|
+
if (server.upgrade(c.req.raw, { data: {
|
|
81
|
+
events,
|
|
82
|
+
url: new URL(c.req.url),
|
|
83
|
+
protocol: c.req.header("sec-websocket-protocol")?.split(",")[0]?.trim() ?? ""
|
|
84
|
+
} })) return new Response(null);
|
|
85
|
+
});
|
|
86
|
+
const websocket = {
|
|
87
|
+
open(ws) {
|
|
88
|
+
const websocketListeners = ws.data.events;
|
|
89
|
+
if (websocketListeners.onOpen) websocketListeners.onOpen(new Event("open"), createWSContext(ws));
|
|
90
|
+
},
|
|
91
|
+
close(ws, code, reason) {
|
|
92
|
+
const websocketListeners = ws.data.events;
|
|
93
|
+
if (websocketListeners.onClose) websocketListeners.onClose(new CloseEvent("close", {
|
|
94
|
+
code,
|
|
95
|
+
reason
|
|
96
|
+
}), createWSContext(ws));
|
|
97
|
+
},
|
|
98
|
+
message(ws, message) {
|
|
99
|
+
const websocketListeners = ws.data.events;
|
|
100
|
+
if (websocketListeners.onMessage) {
|
|
101
|
+
const normalizedReceiveData = typeof message === "string" ? message : message.buffer;
|
|
102
|
+
websocketListeners.onMessage(createWSMessageEvent(normalizedReceiveData), createWSContext(ws));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* @deprecated Import `upgradeWebSocket` and `websocket` directly from `acryl-router/bun` instead.
|
|
108
|
+
* @returns A function to create a Bun WebSocket handler.
|
|
109
|
+
*/
|
|
110
|
+
const createBunWebSocket = () => ({
|
|
111
|
+
upgradeWebSocket,
|
|
112
|
+
websocket
|
|
113
|
+
});
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region ../../plugins/acryl-router/src/core/adapter/bun/conninfo.ts
|
|
116
|
+
/**
|
|
117
|
+
* Get ConnInfo with Bun
|
|
118
|
+
* @param c Context
|
|
119
|
+
* @returns ConnInfo
|
|
120
|
+
*/
|
|
121
|
+
const getConnInfo = (c) => {
|
|
122
|
+
const server = getBunServer(c);
|
|
123
|
+
if (!server) throw new TypeError("env has to include the 2nd argument of fetch.");
|
|
124
|
+
if (typeof server.requestIP !== "function") throw new TypeError("server.requestIP is not a function.");
|
|
125
|
+
const info = server.requestIP(c.req.raw);
|
|
126
|
+
if (!info) return { remote: {} };
|
|
127
|
+
return { remote: {
|
|
128
|
+
address: info.address,
|
|
129
|
+
addressType: info.family === "IPv6" || info.family === "IPv4" ? info.family : void 0,
|
|
130
|
+
port: info.port
|
|
131
|
+
} };
|
|
132
|
+
};
|
|
133
|
+
//#endregion
|
|
134
|
+
export { bunFileSystemModule, createBunWebSocket, getBunServer, getConnInfo, serveStatic, toSSG, upgradeWebSocket, websocket };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { L as MiddlewareHandler, Y as Schema, g as BlankSchema, j as Input, v as Env } from "./context-DS3fYyG-.js";
|
|
2
|
+
import { r as GetConnInfo } from "./types-Dv_nV2cv.js";
|
|
3
|
+
import { t as Acryl } from "./app-D8riatvv.js";
|
|
4
|
+
|
|
5
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-pages/handler.d.ts
|
|
6
|
+
type Params<P extends string = any> = Record<P, string | string[]>;
|
|
7
|
+
type EventContext<Env = {}, P extends string = any, Data = Record<string, unknown>> = {
|
|
8
|
+
request: Request;
|
|
9
|
+
functionPath: string;
|
|
10
|
+
waitUntil: (promise: Promise<unknown>) => void;
|
|
11
|
+
passThroughOnException: () => void;
|
|
12
|
+
props: any;
|
|
13
|
+
next: (input?: Request | string, init?: RequestInit) => Promise<Response>;
|
|
14
|
+
env: Env & {
|
|
15
|
+
ASSETS: {
|
|
16
|
+
fetch: typeof fetch;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
params: Params<P>;
|
|
20
|
+
data: Data;
|
|
21
|
+
};
|
|
22
|
+
declare type PagesFunction<Env = unknown, Params extends string = any, Data extends Record<string, unknown> = Record<string, unknown>> = (context: EventContext<Env, Params, Data>) => Response | Promise<Response>;
|
|
23
|
+
declare const handle: <E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = "/">(app: Acryl<E, S, BasePath>) => PagesFunction<E["Bindings"]>;
|
|
24
|
+
declare function handleMiddleware<E extends Env = {}, P extends string = any, I extends Input = {}>(middleware: MiddlewareHandler<E & {
|
|
25
|
+
Bindings: {
|
|
26
|
+
eventContext: EventContext;
|
|
27
|
+
};
|
|
28
|
+
}, P, I>): PagesFunction<E['Bindings']>;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @description `serveStatic()` is for advanced mode:
|
|
32
|
+
* https://developers.cloudflare.com/pages/platform/functions/advanced-mode/#set-up-a-function
|
|
33
|
+
*/
|
|
34
|
+
declare const serveStatic: () => MiddlewareHandler;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-pages/conninfo.d.ts
|
|
37
|
+
/**
|
|
38
|
+
* Get connection information from Cloudflare Pages
|
|
39
|
+
* @param c - Context
|
|
40
|
+
* @returns Connection information including remote address
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { Acryl } from 'acrylblends'
|
|
44
|
+
* import { handle, getConnInfo } from 'acrylblends/cloudflare-pages'
|
|
45
|
+
*
|
|
46
|
+
* const app = new Acryl()
|
|
47
|
+
*
|
|
48
|
+
* app.get('/', (c) => {
|
|
49
|
+
* const info = getConnInfo(c)
|
|
50
|
+
* return c.text(`Your IP: ${info.remote.address}`)
|
|
51
|
+
* })
|
|
52
|
+
*
|
|
53
|
+
* export const onRequest = handle(app)
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare const getConnInfo: GetConnInfo;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { type EventContext, getConnInfo, handle, handleMiddleware, serveStatic };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { HTTPException } from "./http-exception.js";
|
|
2
|
+
import { t as Context } from "./context-DDO0cfuP.js";
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-pages/handler.ts
|
|
4
|
+
const handle = (app) => (eventContext) => {
|
|
5
|
+
return app.fetch(eventContext.request, {
|
|
6
|
+
...eventContext.env,
|
|
7
|
+
eventContext
|
|
8
|
+
}, {
|
|
9
|
+
waitUntil: eventContext.waitUntil,
|
|
10
|
+
passThroughOnException: eventContext.passThroughOnException,
|
|
11
|
+
props: {}
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
function handleMiddleware(middleware) {
|
|
15
|
+
return async (executionCtx) => {
|
|
16
|
+
const context = new Context(executionCtx.request, {
|
|
17
|
+
env: {
|
|
18
|
+
...executionCtx.env,
|
|
19
|
+
eventContext: executionCtx
|
|
20
|
+
},
|
|
21
|
+
executionCtx
|
|
22
|
+
});
|
|
23
|
+
let response = void 0;
|
|
24
|
+
try {
|
|
25
|
+
response = await middleware(context, async () => {
|
|
26
|
+
try {
|
|
27
|
+
context.res = await executionCtx.next();
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (error instanceof Error) context.error = error;
|
|
30
|
+
else throw error;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error instanceof Error) context.error = error;
|
|
35
|
+
else throw error;
|
|
36
|
+
}
|
|
37
|
+
if (response) return response;
|
|
38
|
+
if (context.error instanceof HTTPException) return context.error.getResponse();
|
|
39
|
+
if (context.error) throw context.error;
|
|
40
|
+
return context.res;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @description `serveStatic()` is for advanced mode:
|
|
46
|
+
* https://developers.cloudflare.com/pages/platform/functions/advanced-mode/#set-up-a-function
|
|
47
|
+
*/
|
|
48
|
+
const serveStatic = () => {
|
|
49
|
+
return async (c) => {
|
|
50
|
+
const res = await c.env.ASSETS.fetch(c.req.raw);
|
|
51
|
+
if (res.status === 404) return c.notFound();
|
|
52
|
+
return res;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-pages/conninfo.ts
|
|
57
|
+
/**
|
|
58
|
+
* Get connection information from Cloudflare Pages
|
|
59
|
+
* @param c - Context
|
|
60
|
+
* @returns Connection information including remote address
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { Acryl } from 'acrylblends'
|
|
64
|
+
* import { handle, getConnInfo } from 'acrylblends/cloudflare-pages'
|
|
65
|
+
*
|
|
66
|
+
* const app = new Acryl()
|
|
67
|
+
*
|
|
68
|
+
* app.get('/', (c) => {
|
|
69
|
+
* const info = getConnInfo(c)
|
|
70
|
+
* return c.text(`Your IP: ${info.remote.address}`)
|
|
71
|
+
* })
|
|
72
|
+
*
|
|
73
|
+
* export const onRequest = handle(app)
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
const getConnInfo = (c) => ({ remote: { address: c.req.header("cf-connecting-ip") } });
|
|
77
|
+
//#endregion
|
|
78
|
+
export { getConnInfo, handle, handleMiddleware, serveStatic };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { L as MiddlewareHandler, v as Env } from "./context-DS3fYyG-.js";
|
|
2
|
+
import { r as GetConnInfo } from "./types-Dv_nV2cv.js";
|
|
3
|
+
import { a as WSEvents, n as UpgradeWebSocket } from "./index-BvFh1Gfx.js";
|
|
4
|
+
import { t as ServeStaticOptions$1 } from "./index-CseujaYI.js";
|
|
5
|
+
|
|
6
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static.d.ts
|
|
7
|
+
type ServeStaticOptions<E extends Env = Env> = ServeStaticOptions$1<E> & {
|
|
8
|
+
namespace?: unknown;
|
|
9
|
+
manifest?: object | string;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static-module.d.ts
|
|
13
|
+
declare const module: <E extends Env = Env>(options: Omit<ServeStaticOptions<E>, "namespace">) => MiddlewareHandler;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/websocket.d.ts
|
|
16
|
+
declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, any, Omit<WSEvents<WebSocket>, 'onOpen'>>;
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/conninfo.d.ts
|
|
19
|
+
declare const getConnInfo: GetConnInfo;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { getConnInfo, module as serveStatic, upgradeWebSocket };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { t as serveStatic$1 } from "./serve-static-Cp5adzGo.js";
|
|
2
|
+
import { WSContext, defineWebSocketHelper } from "./ws.js";
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/utils.ts
|
|
4
|
+
const getContentFromKVAsset = async (path, options) => {
|
|
5
|
+
let ASSET_MANIFEST;
|
|
6
|
+
if (options && options.manifest) if (typeof options.manifest === "string") ASSET_MANIFEST = JSON.parse(options.manifest);
|
|
7
|
+
else ASSET_MANIFEST = options.manifest;
|
|
8
|
+
else if (typeof __STATIC_CONTENT_MANIFEST === "string") ASSET_MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
|
|
9
|
+
else ASSET_MANIFEST = __STATIC_CONTENT_MANIFEST;
|
|
10
|
+
let ASSET_NAMESPACE;
|
|
11
|
+
if (options && options.namespace) ASSET_NAMESPACE = options.namespace;
|
|
12
|
+
else ASSET_NAMESPACE = __STATIC_CONTENT;
|
|
13
|
+
const key = ASSET_MANIFEST[path];
|
|
14
|
+
if (!key) return null;
|
|
15
|
+
const content = await ASSET_NAMESPACE.get(key, { type: "stream" });
|
|
16
|
+
if (!content) return null;
|
|
17
|
+
return content;
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static.ts
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated
|
|
23
|
+
* `serveStatic` in the Cloudflare Workers adapter is deprecated.
|
|
24
|
+
* You can serve static files directly using Cloudflare Static Assets.
|
|
25
|
+
* @see https://developers.cloudflare.com/workers/static-assets/
|
|
26
|
+
* Cloudflare Static Assets is currently in open beta. If this doesn't work for you,
|
|
27
|
+
* please consider using Cloudflare Pages.
|
|
28
|
+
*/
|
|
29
|
+
const serveStatic = (options = {}) => {
|
|
30
|
+
return async function serveStatic(c, next) {
|
|
31
|
+
const getContent = async (path) => {
|
|
32
|
+
return getContentFromKVAsset(path, {
|
|
33
|
+
manifest: options.manifest,
|
|
34
|
+
namespace: options.namespace ? options.namespace : c.env ? c.env.__STATIC_CONTENT : void 0
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return serveStatic$1({
|
|
38
|
+
...options,
|
|
39
|
+
getContent
|
|
40
|
+
})(c, next);
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static-module.ts
|
|
45
|
+
const module = (options) => {
|
|
46
|
+
return serveStatic(options);
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/websocket.ts
|
|
50
|
+
const upgradeWebSocket = defineWebSocketHelper(async (c, events) => {
|
|
51
|
+
if (c.req.header("Upgrade") !== "websocket") return;
|
|
52
|
+
const webSocketPair = new WebSocketPair();
|
|
53
|
+
const client = webSocketPair[0];
|
|
54
|
+
const server = webSocketPair[1];
|
|
55
|
+
const wsContext = new WSContext({
|
|
56
|
+
close: (code, reason) => server.close(code, reason),
|
|
57
|
+
get protocol() {
|
|
58
|
+
return server.protocol;
|
|
59
|
+
},
|
|
60
|
+
raw: server,
|
|
61
|
+
get readyState() {
|
|
62
|
+
return server.readyState;
|
|
63
|
+
},
|
|
64
|
+
url: server.url ? new URL(server.url) : null,
|
|
65
|
+
send: (source) => server.send(source)
|
|
66
|
+
});
|
|
67
|
+
if (events.onClose) server.addEventListener("close", (evt) => events.onClose?.(evt, wsContext));
|
|
68
|
+
if (events.onMessage) server.addEventListener("message", (evt) => events.onMessage?.(evt, wsContext));
|
|
69
|
+
if (events.onError) server.addEventListener("error", (evt) => events.onError?.(evt, wsContext));
|
|
70
|
+
server.accept?.();
|
|
71
|
+
return new Response(null, {
|
|
72
|
+
status: 101,
|
|
73
|
+
webSocket: client
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/conninfo.ts
|
|
78
|
+
const getConnInfo = (c) => ({ remote: { address: c.req.header("cf-connecting-ip") } });
|
|
79
|
+
//#endregion
|
|
80
|
+
export { getConnInfo, module as serveStatic, upgradeWebSocket };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { L as MiddlewareHandler, i as Data, t as Context, v as Env } from "./context-DS3fYyG-.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/middleware/serve-static/index.d.ts
|
|
4
|
+
type ServeStaticOptions<E extends Env = Env> = {
|
|
5
|
+
root?: string;
|
|
6
|
+
path?: string;
|
|
7
|
+
precompressed?: boolean; /** Allow percent signs in the routed request path. Defaults to false. */
|
|
8
|
+
allowPercentInPath?: boolean;
|
|
9
|
+
mimes?: Record<string, string>;
|
|
10
|
+
rewriteRequestPath?: (path: string) => string;
|
|
11
|
+
onFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
|
12
|
+
onNotFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* This middleware is not directly used by the user. Create a wrapper specifying `getContent()` by the environment such as Deno or Bun.
|
|
16
|
+
*/
|
|
17
|
+
declare const serveStatic: <E extends Env = Env>(options: ServeStaticOptions<E> & {
|
|
18
|
+
getContent: (path: string, c: Context<E>) => Promise<Data | Response | null>;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* `join` option according to the runtime. Example `import { join } from 'node:path`. If not specified, it will fall back to the default join function.`
|
|
22
|
+
*/
|
|
23
|
+
join?: (...paths: string[]) => string;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Currently, `pathResolve` is no longer used.
|
|
26
|
+
*/
|
|
27
|
+
pathResolve?: (path: string) => string;
|
|
28
|
+
isDir?: (path: string) => boolean | undefined | Promise<boolean | undefined>;
|
|
29
|
+
}) => MiddlewareHandler;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { serveStatic as n, ServeStaticOptions as t };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { L as MiddlewareHandler, Y as Schema, t as Context, v as Env } from "./context-DS3fYyG-.js";
|
|
2
|
+
import { t as Acryl } from "./app-D8riatvv.js";
|
|
3
|
+
|
|
4
|
+
//#region ../../plugins/acryl-router/src/core/helper/ssg/ssg.d.ts
|
|
5
|
+
declare const DEFAULT_OUTPUT_DIR = "./static";
|
|
6
|
+
/**
|
|
7
|
+
* @experimental
|
|
8
|
+
* `FileSystemModule` is an experimental feature.
|
|
9
|
+
* The API might be changed.
|
|
10
|
+
*/
|
|
11
|
+
interface FileSystemModule {
|
|
12
|
+
writeFile(path: string, data: string | Uint8Array): Promise<void>;
|
|
13
|
+
mkdir(path: string, options: {
|
|
14
|
+
recursive: boolean;
|
|
15
|
+
}): Promise<void | string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @experimental
|
|
19
|
+
* `ToSSGResult` is an experimental feature.
|
|
20
|
+
* The API might be changed.
|
|
21
|
+
*/
|
|
22
|
+
interface ToSSGResult {
|
|
23
|
+
success: boolean;
|
|
24
|
+
files: string[];
|
|
25
|
+
error?: Error;
|
|
26
|
+
}
|
|
27
|
+
declare const defaultExtensionMap: Record<string, string>;
|
|
28
|
+
type BeforeRequestHook = (req: Request) => Request | false | Promise<Request | false>;
|
|
29
|
+
type AfterResponseHook = (res: Response) => Response | false | Promise<Response | false>;
|
|
30
|
+
type AfterGenerateHook = (result: ToSSGResult, fsModule: FileSystemModule, options?: ToSSGOptions) => void | Promise<void>;
|
|
31
|
+
declare const combineBeforeRequestHooks: (hooks: BeforeRequestHook | BeforeRequestHook[]) => BeforeRequestHook;
|
|
32
|
+
declare const combineAfterResponseHooks: (hooks: AfterResponseHook | AfterResponseHook[]) => AfterResponseHook;
|
|
33
|
+
declare const combineAfterGenerateHooks: (hooks: AfterGenerateHook | AfterGenerateHook[], fsModule: FileSystemModule, options?: ToSSGOptions) => AfterGenerateHook;
|
|
34
|
+
interface SSGPlugin {
|
|
35
|
+
beforeRequestHook?: BeforeRequestHook | BeforeRequestHook[];
|
|
36
|
+
afterResponseHook?: AfterResponseHook | AfterResponseHook[];
|
|
37
|
+
afterGenerateHook?: AfterGenerateHook | AfterGenerateHook[];
|
|
38
|
+
}
|
|
39
|
+
interface ToSSGOptions {
|
|
40
|
+
dir?: string;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use plugins[].beforeRequestHook instead.
|
|
43
|
+
*/
|
|
44
|
+
beforeRequestHook?: BeforeRequestHook | BeforeRequestHook[];
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use plugins[].afterResponseHook instead.
|
|
47
|
+
*/
|
|
48
|
+
afterResponseHook?: AfterResponseHook | AfterResponseHook[];
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Use plugins[].afterGenerateHook instead.
|
|
51
|
+
*/
|
|
52
|
+
afterGenerateHook?: AfterGenerateHook | AfterGenerateHook[];
|
|
53
|
+
concurrency?: number;
|
|
54
|
+
extensionMap?: Record<string, string>;
|
|
55
|
+
plugins?: SSGPlugin[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @experimental
|
|
59
|
+
* `fetchRoutesContent` is an experimental feature.
|
|
60
|
+
* The API might be changed.
|
|
61
|
+
*/
|
|
62
|
+
declare const fetchRoutesContent: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Acryl<E, S, BasePath>, beforeRequestHook?: BeforeRequestHook, afterResponseHook?: AfterResponseHook, concurrency?: number) => Generator<Promise<Generator<Promise<{
|
|
63
|
+
routePath: string;
|
|
64
|
+
mimeType: string;
|
|
65
|
+
content: string | ArrayBuffer;
|
|
66
|
+
} | undefined>> | undefined>>;
|
|
67
|
+
declare const saveContentToFile: (data: Promise<{
|
|
68
|
+
routePath: string;
|
|
69
|
+
content: string | ArrayBuffer;
|
|
70
|
+
mimeType: string;
|
|
71
|
+
} | undefined>, fsModule: FileSystemModule, outDir: string, extensionMap?: Record<string, string>) => Promise<string | undefined>;
|
|
72
|
+
/**
|
|
73
|
+
* @experimental
|
|
74
|
+
* `ToSSGInterface` is an experimental feature.
|
|
75
|
+
* The API might be changed.
|
|
76
|
+
*/
|
|
77
|
+
interface ToSSGInterface {
|
|
78
|
+
(app: Acryl<any, any, any>, fsModule: FileSystemModule, options?: ToSSGOptions): Promise<ToSSGResult>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @experimental
|
|
82
|
+
* `ToSSGAdaptorInterface` is an experimental feature.
|
|
83
|
+
* The API might be changed.
|
|
84
|
+
*/
|
|
85
|
+
interface ToSSGAdaptorInterface<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> {
|
|
86
|
+
(app: Acryl<E, S, BasePath>, options?: ToSSGOptions): Promise<ToSSGResult>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @experimental
|
|
90
|
+
* `toSSG` is an experimental feature.
|
|
91
|
+
* The API might be changed.
|
|
92
|
+
*/
|
|
93
|
+
declare const toSSG: ToSSGInterface;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region ../../plugins/acryl-router/src/core/helper/ssg/middleware.d.ts
|
|
96
|
+
declare const X_ACRYL_DISABLE_SSG_HEADER_KEY = "x-acryl-disable-ssg";
|
|
97
|
+
interface SSGParam {
|
|
98
|
+
[key: string]: string;
|
|
99
|
+
}
|
|
100
|
+
type SSGParams = SSGParam[];
|
|
101
|
+
interface SSGParamsMiddleware {
|
|
102
|
+
<E extends Env = Env>(generateParams: (c: Context<E>) => SSGParams | Promise<SSGParams>): MiddlewareHandler<E>;
|
|
103
|
+
<E extends Env = Env>(params: SSGParams): MiddlewareHandler<E>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Define SSG Route
|
|
107
|
+
*/
|
|
108
|
+
declare const ssgParams: SSGParamsMiddleware;
|
|
109
|
+
/**
|
|
110
|
+
* @experimental
|
|
111
|
+
* `isSSGContext` is an experimental feature.
|
|
112
|
+
* The API might be changed.
|
|
113
|
+
*/
|
|
114
|
+
declare const isSSGContext: (c: Context) => boolean;
|
|
115
|
+
/**
|
|
116
|
+
* @experimental
|
|
117
|
+
* `disableSSG` is an experimental feature.
|
|
118
|
+
* The API might be changed.
|
|
119
|
+
*/
|
|
120
|
+
declare const disableSSG: () => MiddlewareHandler;
|
|
121
|
+
/**
|
|
122
|
+
* @experimental
|
|
123
|
+
* `onlySSG` is an experimental feature.
|
|
124
|
+
* The API might be changed.
|
|
125
|
+
*/
|
|
126
|
+
declare const onlySSG: () => MiddlewareHandler;
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region ../../plugins/acryl-router/src/core/helper/ssg/plugins.d.ts
|
|
129
|
+
/**
|
|
130
|
+
* The default plugin that defines the recommended behavior.
|
|
131
|
+
*
|
|
132
|
+
* @experimental
|
|
133
|
+
* `defaultPlugin` is an experimental feature.
|
|
134
|
+
* The API might be changed.
|
|
135
|
+
*/
|
|
136
|
+
declare const defaultPlugin: () => SSGPlugin;
|
|
137
|
+
/**
|
|
138
|
+
* The redirect plugin that generates HTML redirect pages for HTTP redirect responses for status codes 301, 302, 303, 307 and 308.
|
|
139
|
+
*
|
|
140
|
+
* When used with `defaultPlugin`, place `redirectPlugin` before it, because `defaultPlugin` skips non-200 responses.
|
|
141
|
+
*
|
|
142
|
+
* ```ts
|
|
143
|
+
* // ✅ Will work as expected
|
|
144
|
+
* toSSG(app, fs, { plugins: [redirectPlugin(), defaultPlugin()] })
|
|
145
|
+
*
|
|
146
|
+
* // ❌ Will not work as expected
|
|
147
|
+
* toSSG(app, fs, { plugins: [defaultPlugin(), redirectPlugin()] })
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @experimental
|
|
151
|
+
* `redirectPlugin` is an experimental feature.
|
|
152
|
+
* The API might be changed.
|
|
153
|
+
*/
|
|
154
|
+
declare const redirectPlugin: () => SSGPlugin;
|
|
155
|
+
//#endregion
|
|
156
|
+
export { saveContentToFile as C, fetchRoutesContent as S, ToSSGResult as _, isSSGContext as a, combineBeforeRequestHooks as b, AfterGenerateHook as c, DEFAULT_OUTPUT_DIR as d, FileSystemModule as f, ToSSGOptions as g, ToSSGInterface as h, disableSSG as i, AfterResponseHook as l, ToSSGAdaptorInterface as m, redirectPlugin as n, onlySSG as o, SSGPlugin as p, X_ACRYL_DISABLE_SSG_HEADER_KEY as r, ssgParams as s, defaultPlugin as t, BeforeRequestHook as u, combineAfterGenerateHooks as v, toSSG as w, defaultExtensionMap as x, combineAfterResponseHooks as y };
|