@kaanbiryol/crate-server 0.0.0-stage → 0.17.9
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/LICENSE +21 -0
- package/README.md +73 -2
- package/THIRD_PARTY_NOTICES.md +3664 -0
- package/assets/coordinator.mjs +116 -0
- package/assets/credential-revocation.mjs +18 -0
- package/assets/database-upgrade-rules.mjs +42 -0
- package/assets/migrations/README.md +19 -0
- package/assets/qrcode.mjs +1638 -0
- package/assets/schema.sql +368 -0
- package/assets/server-release.json +6 -0
- package/assets/worker-runtime.json +12 -0
- package/assets/worker.mjs +1458 -0
- package/npm-shrinkwrap.json +939 -0
- package/package.json +38 -4
- package/scripts/assets.mjs +33 -0
- package/scripts/commands/data.mjs +80 -0
- package/scripts/commands/devices.mjs +100 -0
- package/scripts/commands/doctor.mjs +127 -0
- package/scripts/commands/service.mjs +19 -0
- package/scripts/commands/setup.mjs +194 -0
- package/scripts/commands/start.mjs +171 -0
- package/scripts/commands/status.mjs +49 -0
- package/scripts/commands/update.mjs +138 -0
- package/scripts/crate-server.mjs +11 -0
- package/scripts/deployment-fingerprint.mjs +13 -0
- package/scripts/local-server-alerts.mjs +53 -0
- package/scripts/local-server-backup-schedule.mjs +153 -0
- package/scripts/local-server-backup.mjs +275 -0
- package/scripts/local-server-cloudflared.mjs +93 -0
- package/scripts/local-server-control.mjs +150 -0
- package/scripts/local-server-devices.mjs +71 -0
- package/scripts/local-server-host-status.mjs +72 -0
- package/scripts/local-server-http.mjs +120 -0
- package/scripts/local-server-install.mjs +22 -0
- package/scripts/local-server-lifecycle.mjs +54 -0
- package/scripts/local-server-lock.mjs +217 -0
- package/scripts/local-server-migrations.mjs +43 -0
- package/scripts/local-server-options.mjs +134 -0
- package/scripts/local-server-pairing.mjs +47 -0
- package/scripts/local-server-process.mjs +77 -0
- package/scripts/local-server-qr.mjs +34 -0
- package/scripts/local-server-quick.mjs +116 -0
- package/scripts/local-server-readiness.mjs +48 -0
- package/scripts/local-server-runtime.mjs +460 -0
- package/scripts/local-server-service.mjs +209 -0
- package/scripts/local-server-style.mjs +12 -0
- package/scripts/local-server-tailscale.mjs +122 -0
- package/scripts/local-server-tunnel.mjs +212 -0
- package/scripts/local-server-watchdog.mjs +37 -0
- package/scripts/local-server-wizard.mjs +100 -0
- package/scripts/local-server.mjs +100 -0
- package/vendor/miniflare/LICENSE +25 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/ArrowClockwise.es-Cs0EHtoR.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Breadcrumbs-BlzUUgNz.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CaretDown.es-r8EMGhHM.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CaretLeft.es-CCxvlwgr.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CaretRight.es-CWeeOO8C.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CaretUpDown.es-Bp73BWZN.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Check.es-B3dV_aVM.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Copy.es-DUyM7PbX.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CopyButton-DdMFsAgv.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CronTriggersContext-CtoQyHCH.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CronTriggersPage-BC2FvZf5.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/DotsThree.es-B9u_qIrH.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Download.es-v8YTKdZh.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/List.es-GlowdvL8.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/ListBullets.es-DrJsrtCL.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/MagnifyingGlass.es-BzOo3pru.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/PaperPlaneTilt.es-DTLdWOnM.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Paperclip.es-6Ysj3lly.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Pencil.es-CDpuGAys.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Plus.es-xOjOjCs5.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/ResourceError-DNadec0F.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Spinner.es-oqUPe-aY.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/TableSelect-DgjN53ZF.js +25 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Trash.es-DTqwcb2_.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Warning.es-CLa-n7LD.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/X.es-BiJFnG31.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_appId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_appId-TnuOHwOA.js +5 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_bucketName-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_bucketName-DMGTgdaZ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_bucketName-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_bucketName-DqCj-aYZ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_bucketName-uYCS7veQ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_captureId-Cb6ggQGG.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_captureId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_captureId-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-BW1__nAw.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-DCj9M_Uf.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-DMGTgdaZ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-uYCS7veQ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_databaseId-BEh2sOY5.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_databaseId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_instanceId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_instanceId-CxJm9jpK.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_instanceId-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_namespaceId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_namespaceId-HT9g0tMq.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_objectId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_objectId-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_objectId-DdmD-NV1.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_workflowName-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_workflowName-DMGTgdaZ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_workflowName-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_workflowName-WgIBBs_w.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_workflowName-uYCS7veQ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/ad-hoc-B9HL0oNk.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/async-t2_zA-v_.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/button-cdxnqcgzwko8ooha-CjoTKpgy.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/checkbox-kt1uojk2f9e0d0h1-D923QL-G.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/clipboard-text-vcbvmtne4zjk4b18-CEoJIuMe.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/configured-BGeRrlYf.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/cron-triggers-ZP5ClwAa.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/dialog-oqh8l3l3zutpibxx-nho54TMC.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/dropdown-ncwhcd912vmone8k-BAT0p_ep.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/email-B-IveBKB.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/events-ClnoiyGH.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/events-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/field-krp6z6vfbkrvufz2-DsLUBjzS.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/format-CjQ0gyEW.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/helpers-Bz2sloWm.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/index-BHW_FKpE.js +30 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/index-CiXL10aq.css +2 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/input-area-no30c09udyjxshu5-T786oEMj.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/input-group-lxdd09p60cf27pe1-BqVz8A4J.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/input-h48k3uagzrgb98au-BF-hE08e.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/label-latndvb1ngem7we8-mWoel0Kk.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/link-DadJAPnd.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/link-provider-mn2voeohon7cj9o4-CNosc_Ni.js +13 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/matchContext-C1eKDtty.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/object._-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/object._-DDwO6NT7.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/object._-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/observability-CC1mP6Xo.js +15 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/observability-CX-6-j6d.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/observability-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/react-BZY8YNV6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/redirect-CckYXsV1.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/routes-BlOyav-b.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/routing-CVthjHxr.js +2 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/routing-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/routing-DMGTgdaZ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/routing-uYCS7veQ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/select-kva5ru5f673kah1m-DQuxH2_G.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/sending-BPjb3S3Y.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/sending-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/switch-ihaydbzem62bey4p-C9M-MPNS.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/table-inweecadl3her7pd-UWLv9e8D.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/text-nmyi1rkwdj37f30f-BLzIhmEO.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/types-DTx0hLYz.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/useCursorPaginatedList-BGUINn38.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/useRouterState-BLq6Ai_6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/favicon.svg +3 -0
- package/vendor/miniflare/dist/local-explorer-ui/index.html +27 -0
- package/vendor/miniflare/dist/src/index.d.ts +14183 -0
- package/vendor/miniflare/dist/src/index.js +123738 -0
- package/vendor/miniflare/dist/src/mdream_edge_bg.wasm +0 -0
- package/vendor/miniflare/dist/src/plugins/artifacts/git-sidecar.js +21071 -0
- package/vendor/miniflare/dist/src/workers/access/access-identity.worker.js +10 -0
- package/vendor/miniflare/dist/src/workers/analytics-engine/analytics-engine.worker.js +21 -0
- package/vendor/miniflare/dist/src/workers/analytics-engine/remote.worker.js +2578 -0
- package/vendor/miniflare/dist/src/workers/artifacts/binding.worker.js +903 -0
- package/vendor/miniflare/dist/src/workers/artifacts/wrapped-binding.worker.js +52 -0
- package/vendor/miniflare/dist/src/workers/assets/assets-kv.worker.js +27 -0
- package/vendor/miniflare/dist/src/workers/assets/assets.worker.js +1525 -0
- package/vendor/miniflare/dist/src/workers/assets/router.worker.js +1883 -0
- package/vendor/miniflare/dist/src/workers/assets/rpc-proxy.worker.js +55 -0
- package/vendor/miniflare/dist/src/workers/browser-rendering/binding.worker.js +453 -0
- package/vendor/miniflare/dist/src/workers/cache/cache-entry-noop.worker.js +18 -0
- package/vendor/miniflare/dist/src/workers/cache/cache-entry.worker.js +24 -0
- package/vendor/miniflare/dist/src/workers/cache/cache.worker.js +652 -0
- package/vendor/miniflare/dist/src/workers/core/dev-control.worker.js +52 -0
- package/vendor/miniflare/dist/src/workers/core/dev-registry-proxy.worker.js +371 -0
- package/vendor/miniflare/dist/src/workers/core/do-wrapper.worker.js +67 -0
- package/vendor/miniflare/dist/src/workers/core/entry.worker.js +5516 -0
- package/vendor/miniflare/dist/src/workers/core/outbound.worker.js +147 -0
- package/vendor/miniflare/dist/src/workers/d1/database.worker.js +298 -0
- package/vendor/miniflare/dist/src/workers/d1/entry.worker.js +143 -0
- package/vendor/miniflare/dist/src/workers/dispatch-namespace/dispatch-namespace-proxy.worker.js +2574 -0
- package/vendor/miniflare/dist/src/workers/dispatch-namespace/dispatch-namespace.worker.js +11 -0
- package/vendor/miniflare/dist/src/workers/email/email-store.worker.js +606 -0
- package/vendor/miniflare/dist/src/workers/email/email.worker.js +26 -0
- package/vendor/miniflare/dist/src/workers/email/send_email.worker.js +3703 -0
- package/vendor/miniflare/dist/src/workers/flagship/binding.worker.js +394 -0
- package/vendor/miniflare/dist/src/workers/flagship/object.worker.js +349 -0
- package/vendor/miniflare/dist/src/workers/hello-world/binding.worker.js +18 -0
- package/vendor/miniflare/dist/src/workers/hello-world/object.worker.js +13 -0
- package/vendor/miniflare/dist/src/workers/images/images.worker.js +450 -0
- package/vendor/miniflare/dist/src/workers/k2/binding.worker.js +2583 -0
- package/vendor/miniflare/dist/src/workers/kv/namespace.worker.js +323 -0
- package/vendor/miniflare/dist/src/workers/kv/sites.worker.js +148 -0
- package/vendor/miniflare/dist/src/workers/local-explorer/explorer.worker.js +17275 -0
- package/vendor/miniflare/dist/src/workers/observability/collector.worker.js +725 -0
- package/vendor/miniflare/dist/src/workers/pipelines/pipeline.worker.js +9 -0
- package/vendor/miniflare/dist/src/workers/queues/broker.worker.js +391 -0
- package/vendor/miniflare/dist/src/workers/r2/bucket.worker.js +1171 -0
- package/vendor/miniflare/dist/src/workers/r2/public.worker.js +1319 -0
- package/vendor/miniflare/dist/src/workers/r2/s3/index.worker.js +11128 -0
- package/vendor/miniflare/dist/src/workers/ratelimit/ratelimit-object.worker.js +55 -0
- package/vendor/miniflare/dist/src/workers/ratelimit/ratelimit.worker.js +69 -0
- package/vendor/miniflare/dist/src/workers/secrets-store/secret.worker.js +64 -0
- package/vendor/miniflare/dist/src/workers/shared/index.worker.js +730 -0
- package/vendor/miniflare/dist/src/workers/shared/object-entry.worker.js +33 -0
- package/vendor/miniflare/dist/src/workers/shared/remote-proxy-client.worker.js +2698 -0
- package/vendor/miniflare/dist/src/workers/shared/zod.worker.js +15459 -0
- package/vendor/miniflare/dist/src/workers/stream/binding.worker.js +282 -0
- package/vendor/miniflare/dist/src/workers/stream/object.worker.js +479 -0
- package/vendor/miniflare/dist/src/workers/workflows/binding.worker.js +5137 -0
- package/vendor/miniflare/dist/src/workers/workflows/wrapped-binding.worker.js +111 -0
- package/vendor/miniflare/package.json +135 -0
|
@@ -0,0 +1,1319 @@
|
|
|
1
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/middleware/cors/index.js
|
|
2
|
+
var cors = (options) => {
|
|
3
|
+
let opts = {
|
|
4
|
+
origin: "*",
|
|
5
|
+
allowMethods: [
|
|
6
|
+
"GET",
|
|
7
|
+
"HEAD",
|
|
8
|
+
"PUT",
|
|
9
|
+
"POST",
|
|
10
|
+
"DELETE",
|
|
11
|
+
"PATCH",
|
|
12
|
+
"QUERY"
|
|
13
|
+
],
|
|
14
|
+
allowHeaders: [],
|
|
15
|
+
exposeHeaders: [],
|
|
16
|
+
...options
|
|
17
|
+
}, exposeHeadersStr = opts.exposeHeaders?.length ? opts.exposeHeaders.join(",") : void 0, allowHeadersStr = opts.allowHeaders?.length ? opts.allowHeaders.join(",") : void 0, findAllowOrigin = /* @__PURE__ */ ((optsOrigin) => typeof optsOrigin == "string" ? optsOrigin === "*" ? () => optsOrigin : (origin) => optsOrigin === origin ? origin : null : typeof optsOrigin == "function" ? optsOrigin : (origin) => optsOrigin.includes(origin) ? origin : null)(opts.origin), findAllowMethods = ((optsAllowMethods) => {
|
|
18
|
+
if (typeof optsAllowMethods == "function") return async (origin, c) => (await optsAllowMethods(origin, c)).join(",");
|
|
19
|
+
if (Array.isArray(optsAllowMethods)) {
|
|
20
|
+
let methodsStr = optsAllowMethods.join(",");
|
|
21
|
+
return () => methodsStr;
|
|
22
|
+
} else return () => "";
|
|
23
|
+
})(opts.allowMethods);
|
|
24
|
+
return async function(c, next) {
|
|
25
|
+
function set(key, value) {
|
|
26
|
+
c.res.headers.set(key, value);
|
|
27
|
+
}
|
|
28
|
+
let allowOrigin = await findAllowOrigin(c.req.header("origin") || "", c);
|
|
29
|
+
if (allowOrigin && set("Access-Control-Allow-Origin", allowOrigin), opts.credentials && set("Access-Control-Allow-Credentials", "true"), exposeHeadersStr && set("Access-Control-Expose-Headers", exposeHeadersStr), c.req.method === "OPTIONS") {
|
|
30
|
+
opts.origin !== "*" && c.res.headers.append("Vary", "Origin"), opts.maxAge != null && set("Access-Control-Max-Age", opts.maxAge.toString());
|
|
31
|
+
let allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
|
|
32
|
+
allowMethods && set("Access-Control-Allow-Methods", allowMethods);
|
|
33
|
+
let headersStr = allowHeadersStr;
|
|
34
|
+
if (!headersStr) {
|
|
35
|
+
let requestHeaders = c.req.header("Access-Control-Request-Headers");
|
|
36
|
+
requestHeaders && (headersStr = requestHeaders.split(",").map((h) => h.trim()).join(","));
|
|
37
|
+
}
|
|
38
|
+
return headersStr && (set("Access-Control-Allow-Headers", headersStr), c.res.headers.append("Vary", "Access-Control-Request-Headers")), c.res.headers.delete("Content-Length"), c.res.headers.delete("Content-Type"), new Response(null, {
|
|
39
|
+
headers: c.res.headers,
|
|
40
|
+
status: 204,
|
|
41
|
+
statusText: "No Content"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
await next(), opts.origin !== "*" && c.header("Vary", "Origin", { append: !0 });
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/compose.js
|
|
49
|
+
var compose = (middleware, onError, onNotFound) => (context, next) => {
|
|
50
|
+
let index = -1;
|
|
51
|
+
return dispatch(0);
|
|
52
|
+
async function dispatch(i) {
|
|
53
|
+
if (i <= index) throw new Error("next() called multiple times");
|
|
54
|
+
index = i;
|
|
55
|
+
let res, isError = !1, handler;
|
|
56
|
+
if (middleware[i] ? (handler = middleware[i][0][0], context.req.routeIndex = i) : handler = i === middleware.length && next || void 0, handler) try {
|
|
57
|
+
res = await handler(context, () => dispatch(i + 1));
|
|
58
|
+
} catch (err) {
|
|
59
|
+
if (err instanceof Error && onError)
|
|
60
|
+
context.error = err, res = await onError(err, context), isError = !0;
|
|
61
|
+
else throw err;
|
|
62
|
+
}
|
|
63
|
+
else context.finalized === !1 && onNotFound && (res = await onNotFound(context));
|
|
64
|
+
return res && (context.finalized === !1 || isError) && (context.res = res), context;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/utils/url.js
|
|
69
|
+
var splitPath = (path) => {
|
|
70
|
+
let paths = path.split("/");
|
|
71
|
+
return paths[0] === "" && paths.shift(), paths;
|
|
72
|
+
}, splitRoutingPath = (routePath) => {
|
|
73
|
+
let { groups, path } = extractGroupsFromPath(routePath), paths = splitPath(path);
|
|
74
|
+
return replaceGroupMarks(paths, groups);
|
|
75
|
+
}, extractGroupsFromPath = (path) => {
|
|
76
|
+
let groups = [];
|
|
77
|
+
return path = path.replace(/\{[^}]+\}/g, (match, index) => {
|
|
78
|
+
let mark = `@${index}`;
|
|
79
|
+
return groups.push([mark, match]), mark;
|
|
80
|
+
}), {
|
|
81
|
+
groups,
|
|
82
|
+
path
|
|
83
|
+
};
|
|
84
|
+
}, replaceGroupMarks = (paths, groups) => {
|
|
85
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
86
|
+
let [mark] = groups[i];
|
|
87
|
+
for (let j = paths.length - 1; j >= 0; j--) if (paths[j].includes(mark)) {
|
|
88
|
+
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return paths;
|
|
93
|
+
}, patternCache = {}, getPattern = (label, next) => {
|
|
94
|
+
if (label === "*") return "*";
|
|
95
|
+
let match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
96
|
+
if (match) {
|
|
97
|
+
let cacheKey = `${label}#${next}`;
|
|
98
|
+
return patternCache[cacheKey] || (match[2] ? patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [
|
|
99
|
+
cacheKey,
|
|
100
|
+
match[1],
|
|
101
|
+
new RegExp(`^${match[2]}(?=/${next})`)
|
|
102
|
+
] : [
|
|
103
|
+
label,
|
|
104
|
+
match[1],
|
|
105
|
+
new RegExp(`^${match[2]}$`)
|
|
106
|
+
] : patternCache[cacheKey] = [
|
|
107
|
+
label,
|
|
108
|
+
match[1],
|
|
109
|
+
!0
|
|
110
|
+
]), patternCache[cacheKey];
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
}, tryDecode = (str, decoder) => {
|
|
114
|
+
try {
|
|
115
|
+
return decoder(str);
|
|
116
|
+
} catch {
|
|
117
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
118
|
+
try {
|
|
119
|
+
return decoder(match);
|
|
120
|
+
} catch {
|
|
121
|
+
return match;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}, tryDecodeURI = (str) => tryDecode(str, decodeURI), getPath = (request) => {
|
|
126
|
+
let url = request.url, start = url.indexOf("/", url.indexOf(":") + 4), i = start;
|
|
127
|
+
for (; i < url.length; i++) {
|
|
128
|
+
let charCode = url.charCodeAt(i);
|
|
129
|
+
if (charCode === 37) {
|
|
130
|
+
let queryIndex = url.indexOf("?", i), hashIndex = url.indexOf("#", i), end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex), path = url.slice(start, end);
|
|
131
|
+
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
132
|
+
} else if (charCode === 63 || charCode === 35) break;
|
|
133
|
+
}
|
|
134
|
+
return url.slice(start, i);
|
|
135
|
+
};
|
|
136
|
+
var getPathNoStrict = (request) => {
|
|
137
|
+
let result = getPath(request);
|
|
138
|
+
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
139
|
+
}, stripPathPrefix = (rawPath, decodedPath, prefixLength) => {
|
|
140
|
+
rawPath.at(-1) === "/" && decodedPath.at(-1) !== "/" && (rawPath = rawPath.slice(0, -1));
|
|
141
|
+
let index = 0;
|
|
142
|
+
for (let i = decodedPath.indexOf("/"); i !== -1 && i < prefixLength; i = decodedPath.indexOf("/", i + 1))
|
|
143
|
+
if (index = rawPath.indexOf("/", index + 1), index === -1) return "/";
|
|
144
|
+
return rawPath.slice(index) || "/";
|
|
145
|
+
}, mergePath = (base, sub, ...rest) => (rest.length && (sub = mergePath(sub, ...rest)), `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`);
|
|
146
|
+
var tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str, _decodeURI = (value) => (value.indexOf("+") !== -1 && (value = value.replace(/\+/g, " ")), tryDecodeURIComponent(value)), _getQueryParam = (url, key, multiple) => {
|
|
147
|
+
let hashIndex = url.indexOf("#", 8);
|
|
148
|
+
hashIndex !== -1 && (url = url.slice(0, hashIndex));
|
|
149
|
+
let encoded;
|
|
150
|
+
if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
|
|
151
|
+
let queryIndex = url.indexOf("?", 8), keyIndex2 = queryIndex;
|
|
152
|
+
if (keyIndex2 === -1) return;
|
|
153
|
+
for (url.startsWith(key, keyIndex2 + 1) || (keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1)); keyIndex2 !== -1; ) {
|
|
154
|
+
let trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
155
|
+
if (trailingKeyCode === 61 || trailingKeyCode === 38 || isNaN(trailingKeyCode)) {
|
|
156
|
+
if (keyIndex2 > queryIndex && /(?:^|&)[^=&]*[%+]/.test(url.slice(queryIndex + 1, keyIndex2))) break;
|
|
157
|
+
if (trailingKeyCode === 61) {
|
|
158
|
+
let valueIndex = keyIndex2 + key.length + 2, endIndex = url.indexOf("&", valueIndex);
|
|
159
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
160
|
+
}
|
|
161
|
+
return "";
|
|
162
|
+
}
|
|
163
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
164
|
+
}
|
|
165
|
+
if (encoded = /[%+]/.test(url), !encoded) return;
|
|
166
|
+
}
|
|
167
|
+
let results = /* @__PURE__ */ Object.create(null);
|
|
168
|
+
encoded ??= /[%+]/.test(url);
|
|
169
|
+
let keyIndex = url.indexOf("?", 8);
|
|
170
|
+
for (; keyIndex !== -1; ) {
|
|
171
|
+
let nextKeyIndex = url.indexOf("&", keyIndex + 1), valueIndex = url.indexOf("=", keyIndex);
|
|
172
|
+
valueIndex > nextKeyIndex && nextKeyIndex !== -1 && (valueIndex = -1);
|
|
173
|
+
let name = url.slice(keyIndex + 1, valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex);
|
|
174
|
+
if (encoded && (name = _decodeURI(name)), keyIndex = nextKeyIndex, name === "") continue;
|
|
175
|
+
let value;
|
|
176
|
+
valueIndex === -1 ? value = "" : (value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex), encoded && (value = _decodeURI(value))), multiple ? (results[name] && Array.isArray(results[name]) || (results[name] = []), results[name].push(value)) : results[name] ??= value;
|
|
177
|
+
}
|
|
178
|
+
return key ? results[key] : results;
|
|
179
|
+
}, getQueryParam = _getQueryParam, getQueryParams = (url, key) => _getQueryParam(url, key, !0), decodeURIComponent_ = decodeURIComponent;
|
|
180
|
+
|
|
181
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/request/constants.js
|
|
182
|
+
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
183
|
+
|
|
184
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/utils/buffer.js
|
|
185
|
+
var bufferToFormData = (arrayBuffer, contentType) => new Response(arrayBuffer, { headers: { "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase()) } }).formData();
|
|
186
|
+
|
|
187
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/utils/body.js
|
|
188
|
+
var MAX_NESTED_OBJECTS = 1e4, isRawRequest = (request) => "headers" in request, parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
189
|
+
let { all = !1, dot = !1 } = options, mediaType = (isRawRequest(request) ? request.headers : request.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
|
|
190
|
+
return mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded" ? parseFormData(request, {
|
|
191
|
+
all,
|
|
192
|
+
dot
|
|
193
|
+
}) : {};
|
|
194
|
+
};
|
|
195
|
+
async function parseFormData(request, options) {
|
|
196
|
+
if (!isRawRequest(request) && request.bodyCache.formData) return convertFormDataToBodyData(await request.bodyCache.formData, options);
|
|
197
|
+
let headers = isRawRequest(request) ? request.headers : request.raw.headers, arrayBuffer = await request.arrayBuffer(), formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
|
|
198
|
+
isRawRequest(request) || (request.bodyCache.formData = formDataPromise);
|
|
199
|
+
let formData = await formDataPromise;
|
|
200
|
+
return formData ? convertFormDataToBodyData(formData, options) : {};
|
|
201
|
+
}
|
|
202
|
+
function convertFormDataToBodyData(formData, options) {
|
|
203
|
+
let form = /* @__PURE__ */ Object.create(null), nestingState = { count: 0 };
|
|
204
|
+
return formData.forEach((value, key) => {
|
|
205
|
+
options.all || key.endsWith("[]") ? handleParsingAllValues(form, key, value) : form[key] = value;
|
|
206
|
+
}), options.dot && Object.entries(form).forEach(([key, value]) => {
|
|
207
|
+
key.includes(".") && (handleParsingNestedValues(form, key, value, nestingState), delete form[key]);
|
|
208
|
+
}), form;
|
|
209
|
+
}
|
|
210
|
+
var handleParsingAllValues = (form, key, value) => {
|
|
211
|
+
form[key] !== void 0 ? Array.isArray(form[key]) ? form[key].push(value) : form[key] = [form[key], value] : key.endsWith("[]") ? form[key] = [value] : form[key] = value;
|
|
212
|
+
}, handleParsingNestedValues = (form, key, value, state) => {
|
|
213
|
+
if (/(?:^|\.)__proto__\./.test(key)) return;
|
|
214
|
+
let nestedForm = form, keys = key.split(".", 34);
|
|
215
|
+
keys.length > 33 && throwNestingLimitExceeded(), keys.forEach((key2, index) => {
|
|
216
|
+
index === keys.length - 1 ? nestedForm[key2] = value : ((!nestedForm[key2] || typeof nestedForm[key2] != "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) && (state.count++ >= MAX_NESTED_OBJECTS && throwNestingLimitExceeded(), nestedForm[key2] = /* @__PURE__ */ Object.create(null)), nestedForm = nestedForm[key2]);
|
|
217
|
+
});
|
|
218
|
+
}, throwNestingLimitExceeded = () => {
|
|
219
|
+
throw new Error("Nesting limit exceeded");
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/request.js
|
|
223
|
+
var HonoRequest = class {
|
|
224
|
+
/**
|
|
225
|
+
* `.raw` can get the raw Request object.
|
|
226
|
+
*
|
|
227
|
+
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* // For Cloudflare Workers
|
|
232
|
+
* app.post('/', async (c) => {
|
|
233
|
+
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
234
|
+
* ...
|
|
235
|
+
* })
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
raw;
|
|
239
|
+
#validatedData;
|
|
240
|
+
#matchResult;
|
|
241
|
+
routeIndex = 0;
|
|
242
|
+
/**
|
|
243
|
+
* `.path` can get the pathname of the request.
|
|
244
|
+
*
|
|
245
|
+
* @see {@link https://hono.dev/docs/api/request#path}
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* app.get('/about/me', (c) => {
|
|
250
|
+
* const pathname = c.req.path // `/about/me`
|
|
251
|
+
* })
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
path;
|
|
255
|
+
bodyCache = {};
|
|
256
|
+
constructor(request, path = "/", matchResult = [[]]) {
|
|
257
|
+
this.raw = request, this.path = path, this.#matchResult = matchResult;
|
|
258
|
+
}
|
|
259
|
+
param(key) {
|
|
260
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
261
|
+
}
|
|
262
|
+
#getDecodedParam(key) {
|
|
263
|
+
let paramKey = this.#matchResult[0][this.routeIndex]?.[1][key], param = this.#getParamValue(paramKey);
|
|
264
|
+
return param && tryDecodeURIComponent(param);
|
|
265
|
+
}
|
|
266
|
+
#getAllDecodedParams() {
|
|
267
|
+
let decoded = {}, keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
|
|
268
|
+
for (let key of keys) {
|
|
269
|
+
let value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
270
|
+
value !== void 0 && (decoded[key] = tryDecodeURIComponent(value));
|
|
271
|
+
}
|
|
272
|
+
return decoded;
|
|
273
|
+
}
|
|
274
|
+
#getParamValue(paramKey) {
|
|
275
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
276
|
+
}
|
|
277
|
+
query(key) {
|
|
278
|
+
return getQueryParam(this.url, key);
|
|
279
|
+
}
|
|
280
|
+
queries(key) {
|
|
281
|
+
return getQueryParams(this.url, key);
|
|
282
|
+
}
|
|
283
|
+
header(name) {
|
|
284
|
+
if (name) return this.raw.headers.get(name) ?? void 0;
|
|
285
|
+
let headerData = /* @__PURE__ */ Object.create(null);
|
|
286
|
+
return this.raw.headers.forEach((value, key) => {
|
|
287
|
+
headerData[key] = value;
|
|
288
|
+
}), headerData;
|
|
289
|
+
}
|
|
290
|
+
async parseBody(options) {
|
|
291
|
+
return parseBody(this, options);
|
|
292
|
+
}
|
|
293
|
+
#cachedBody = (key) => {
|
|
294
|
+
let { bodyCache, raw: raw2 } = this, cachedBody = bodyCache[key];
|
|
295
|
+
if (cachedBody) return cachedBody;
|
|
296
|
+
for (let anyCachedKey in bodyCache) return bodyCache[anyCachedKey].then((body) => {
|
|
297
|
+
anyCachedKey === "json" && (body = JSON.stringify(body));
|
|
298
|
+
let contentType = anyCachedKey === "formData" ? void 0 : raw2.headers.get("content-type");
|
|
299
|
+
return new Response(body, { headers: contentType ? { "Content-Type": contentType } : void 0 })[key]();
|
|
300
|
+
});
|
|
301
|
+
return bodyCache[key] = raw2[key]();
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* `.json()` can parse Request body of type `application/json`
|
|
305
|
+
*
|
|
306
|
+
* @see {@link https://hono.dev/docs/api/request#json}
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* app.post('/entry', async (c) => {
|
|
311
|
+
* const body = await c.req.json()
|
|
312
|
+
* })
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
json() {
|
|
316
|
+
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* `.text()` can parse Request body of type `text/plain`
|
|
320
|
+
*
|
|
321
|
+
* @see {@link https://hono.dev/docs/api/request#text}
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```ts
|
|
325
|
+
* app.post('/entry', async (c) => {
|
|
326
|
+
* const body = await c.req.text()
|
|
327
|
+
* })
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
text() {
|
|
331
|
+
return this.#cachedBody("text");
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
335
|
+
*
|
|
336
|
+
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```ts
|
|
340
|
+
* app.post('/entry', async (c) => {
|
|
341
|
+
* const body = await c.req.arrayBuffer()
|
|
342
|
+
* })
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
arrayBuffer() {
|
|
346
|
+
return this.#cachedBody("arrayBuffer");
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* `.bytes()` parses the request body as a `Uint8Array`.
|
|
350
|
+
*
|
|
351
|
+
* @see {@link https://hono.dev/docs/api/request#bytes}
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* app.post('/entry', async (c) => {
|
|
356
|
+
* const body = await c.req.bytes()
|
|
357
|
+
* })
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
bytes() {
|
|
361
|
+
return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Parses the request body as a `Blob`.
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* app.post('/entry', async (c) => {
|
|
368
|
+
* const body = await c.req.blob();
|
|
369
|
+
* });
|
|
370
|
+
* ```
|
|
371
|
+
* @see https://hono.dev/docs/api/request#blob
|
|
372
|
+
*/
|
|
373
|
+
blob() {
|
|
374
|
+
return this.#cachedBody("blob");
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Parses the request body as `FormData`.
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* app.post('/entry', async (c) => {
|
|
381
|
+
* const body = await c.req.formData();
|
|
382
|
+
* });
|
|
383
|
+
* ```
|
|
384
|
+
* @see https://hono.dev/docs/api/request#formdata
|
|
385
|
+
*/
|
|
386
|
+
formData() {
|
|
387
|
+
return this.#cachedBody("formData");
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Adds validated data to the request.
|
|
391
|
+
*
|
|
392
|
+
* @param target - The target of the validation.
|
|
393
|
+
* @param data - The validated data to add.
|
|
394
|
+
*/
|
|
395
|
+
addValidatedData(target, data) {
|
|
396
|
+
(this.#validatedData ??= {})[target] = data;
|
|
397
|
+
}
|
|
398
|
+
valid(target) {
|
|
399
|
+
return this.#validatedData?.[target];
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* `.url` can get the request url strings.
|
|
403
|
+
*
|
|
404
|
+
* @see {@link https://hono.dev/docs/api/request#url}
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```ts
|
|
408
|
+
* app.get('/about/me', (c) => {
|
|
409
|
+
* const url = c.req.url // `http://localhost:8787/about/me`
|
|
410
|
+
* ...
|
|
411
|
+
* })
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
get url() {
|
|
415
|
+
return this.raw.url;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* `.method` can get the method name of the request.
|
|
419
|
+
*
|
|
420
|
+
* @see {@link https://hono.dev/docs/api/request#method}
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```ts
|
|
424
|
+
* app.get('/about/me', (c) => {
|
|
425
|
+
* const method = c.req.method // `GET`
|
|
426
|
+
* })
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
get method() {
|
|
430
|
+
return this.raw.method;
|
|
431
|
+
}
|
|
432
|
+
get [GET_MATCH_RESULT]() {
|
|
433
|
+
return this.#matchResult;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* `.matchedRoutes` can return a matched route in the handler
|
|
437
|
+
*
|
|
438
|
+
* @deprecated
|
|
439
|
+
*
|
|
440
|
+
* Use matchedRoutes helper defined in "hono/route" instead.
|
|
441
|
+
*
|
|
442
|
+
* @see {@link https://hono.dev/docs/api/request#matchedroutes}
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```ts
|
|
446
|
+
* app.use('*', async function logger(c, next) {
|
|
447
|
+
* await next()
|
|
448
|
+
* c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
|
|
449
|
+
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
450
|
+
* console.log(
|
|
451
|
+
* method,
|
|
452
|
+
* ' ',
|
|
453
|
+
* path,
|
|
454
|
+
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
455
|
+
* name,
|
|
456
|
+
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
457
|
+
* )
|
|
458
|
+
* })
|
|
459
|
+
* })
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
get matchedRoutes() {
|
|
463
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* `.routePath` can retrieve the path registered within the handler
|
|
467
|
+
*
|
|
468
|
+
* @deprecated
|
|
469
|
+
*
|
|
470
|
+
* Use routePath helper defined in "hono/route" instead.
|
|
471
|
+
*
|
|
472
|
+
* @see {@link https://hono.dev/docs/api/request#routepath}
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```ts
|
|
476
|
+
* app.get('/posts/:id', (c) => {
|
|
477
|
+
* return c.json({ path: c.req.routePath })
|
|
478
|
+
* })
|
|
479
|
+
* ```
|
|
480
|
+
*/
|
|
481
|
+
get routePath() {
|
|
482
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/utils/html.js
|
|
487
|
+
var HtmlEscapedCallbackPhase = {
|
|
488
|
+
Stringify: 1,
|
|
489
|
+
BeforeStream: 2,
|
|
490
|
+
Stream: 3
|
|
491
|
+
}, raw = (value, callbacks) => {
|
|
492
|
+
let escapedString = new String(value);
|
|
493
|
+
return escapedString.isEscaped = !0, escapedString.callbacks = callbacks, escapedString;
|
|
494
|
+
};
|
|
495
|
+
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
496
|
+
typeof str == "object" && !(str instanceof String) && (str instanceof Promise || (str = str.toString()), str instanceof Promise && (str = await str));
|
|
497
|
+
let callbacks = str.callbacks;
|
|
498
|
+
if (!callbacks?.length) return Promise.resolve(str);
|
|
499
|
+
buffer ? buffer[0] += str : buffer = [str];
|
|
500
|
+
let resStr = Promise.all(callbacks.map((c) => c({
|
|
501
|
+
phase,
|
|
502
|
+
buffer,
|
|
503
|
+
context
|
|
504
|
+
}))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, !1, context, buffer))).then(() => buffer[0]));
|
|
505
|
+
return preserveCallbacks ? raw(await resStr, callbacks) : resStr;
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/context.js
|
|
509
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8", setDefaultContentType = (contentType, headers) => ({
|
|
510
|
+
"Content-Type": contentType,
|
|
511
|
+
...headers
|
|
512
|
+
}), createResponseInstance = (body, init) => new Response(body, init), Context = class {
|
|
513
|
+
#rawRequest;
|
|
514
|
+
#req;
|
|
515
|
+
/**
|
|
516
|
+
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
|
517
|
+
*
|
|
518
|
+
* @see {@link https://hono.dev/docs/api/context#env}
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```ts
|
|
522
|
+
* // Environment object for Cloudflare Workers
|
|
523
|
+
* app.get('*', async c => {
|
|
524
|
+
* const counter = c.env.COUNTER
|
|
525
|
+
* })
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
env = {};
|
|
529
|
+
#var;
|
|
530
|
+
finalized = !1;
|
|
531
|
+
/**
|
|
532
|
+
* `.error` can get the error object from the middleware if the Handler throws an error.
|
|
533
|
+
*
|
|
534
|
+
* @see {@link https://hono.dev/docs/api/context#error}
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```ts
|
|
538
|
+
* app.use('*', async (c, next) => {
|
|
539
|
+
* await next()
|
|
540
|
+
* if (c.error) {
|
|
541
|
+
* // do something...
|
|
542
|
+
* }
|
|
543
|
+
* })
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
error;
|
|
547
|
+
#status;
|
|
548
|
+
#executionCtx;
|
|
549
|
+
#res;
|
|
550
|
+
#layout;
|
|
551
|
+
#renderer;
|
|
552
|
+
#notFoundHandler;
|
|
553
|
+
#preparedHeaders;
|
|
554
|
+
#matchResult;
|
|
555
|
+
#path;
|
|
556
|
+
/**
|
|
557
|
+
* Creates an instance of the Context class.
|
|
558
|
+
*
|
|
559
|
+
* @param req - The Request object.
|
|
560
|
+
* @param options - Optional configuration options for the context.
|
|
561
|
+
*/
|
|
562
|
+
constructor(req, options) {
|
|
563
|
+
this.#rawRequest = req, options && (this.#executionCtx = options.executionCtx, this.env = options.env, this.#notFoundHandler = options.notFoundHandler, this.#path = options.path, this.#matchResult = options.matchResult);
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* `.req` is the instance of {@link HonoRequest}.
|
|
567
|
+
*/
|
|
568
|
+
get req() {
|
|
569
|
+
return this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult), this.#req;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* @see {@link https://hono.dev/docs/api/context#event}
|
|
573
|
+
* The FetchEvent associated with the current request.
|
|
574
|
+
*
|
|
575
|
+
* @throws Will throw an error if the context does not have a FetchEvent.
|
|
576
|
+
*/
|
|
577
|
+
get event() {
|
|
578
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx) return this.#executionCtx;
|
|
579
|
+
throw Error("This context has no FetchEvent");
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* @see {@link https://hono.dev/docs/api/context#executionctx}
|
|
583
|
+
* The ExecutionContext associated with the current request.
|
|
584
|
+
*
|
|
585
|
+
* @throws Will throw an error if the context does not have an ExecutionContext.
|
|
586
|
+
*/
|
|
587
|
+
get executionCtx() {
|
|
588
|
+
if (this.#executionCtx) return this.#executionCtx;
|
|
589
|
+
throw Error("This context has no ExecutionContext");
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* @see {@link https://hono.dev/docs/api/context#res}
|
|
593
|
+
* The Response object for the current request.
|
|
594
|
+
*/
|
|
595
|
+
get res() {
|
|
596
|
+
return this.#res ||= createResponseInstance(null, { headers: this.#preparedHeaders ??= new Headers() });
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Sets the Response object for the current request.
|
|
600
|
+
*
|
|
601
|
+
* @param _res - The Response object to set.
|
|
602
|
+
*/
|
|
603
|
+
set res(_res) {
|
|
604
|
+
if (this.#res && _res) {
|
|
605
|
+
_res = createResponseInstance(_res.body, _res);
|
|
606
|
+
for (let [k, v] of this.#res.headers.entries())
|
|
607
|
+
if (k !== "content-type")
|
|
608
|
+
if (k === "set-cookie") {
|
|
609
|
+
let cookies = this.#res.headers.getSetCookie();
|
|
610
|
+
_res.headers.delete("set-cookie");
|
|
611
|
+
for (let cookie of cookies) _res.headers.append("set-cookie", cookie);
|
|
612
|
+
} else _res.headers.set(k, v);
|
|
613
|
+
}
|
|
614
|
+
this.#res = _res, this.finalized = !0;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* `.render()` can create a response within a layout.
|
|
618
|
+
*
|
|
619
|
+
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```ts
|
|
623
|
+
* app.get('/', (c) => {
|
|
624
|
+
* return c.render('Hello!')
|
|
625
|
+
* })
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
render = (...args) => (this.#renderer ??= (content) => this.html(content), this.#renderer(...args));
|
|
629
|
+
/**
|
|
630
|
+
* Sets the layout for the response.
|
|
631
|
+
*
|
|
632
|
+
* @param layout - The layout to set.
|
|
633
|
+
* @returns The layout function.
|
|
634
|
+
*/
|
|
635
|
+
setLayout = (layout) => this.#layout = layout;
|
|
636
|
+
/**
|
|
637
|
+
* Gets the current layout for the response.
|
|
638
|
+
*
|
|
639
|
+
* @returns The current layout function.
|
|
640
|
+
*/
|
|
641
|
+
getLayout = () => this.#layout;
|
|
642
|
+
/**
|
|
643
|
+
* `.setRenderer()` can set the layout in the custom middleware.
|
|
644
|
+
*
|
|
645
|
+
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* ```tsx
|
|
649
|
+
* app.use('*', async (c, next) => {
|
|
650
|
+
* c.setRenderer((content) => {
|
|
651
|
+
* return c.html(
|
|
652
|
+
* <html>
|
|
653
|
+
* <body>
|
|
654
|
+
* <p>{content}</p>
|
|
655
|
+
* </body>
|
|
656
|
+
* </html>
|
|
657
|
+
* )
|
|
658
|
+
* })
|
|
659
|
+
* await next()
|
|
660
|
+
* })
|
|
661
|
+
* ```
|
|
662
|
+
*/
|
|
663
|
+
setRenderer = (renderer) => {
|
|
664
|
+
this.#renderer = renderer;
|
|
665
|
+
};
|
|
666
|
+
/**
|
|
667
|
+
* `.header()` can set headers.
|
|
668
|
+
*
|
|
669
|
+
* @see {@link https://hono.dev/docs/api/context#header}
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* ```ts
|
|
673
|
+
* app.get('/welcome', (c) => {
|
|
674
|
+
* // Set headers
|
|
675
|
+
* c.header('X-Message', 'Hello!')
|
|
676
|
+
* c.header('Content-Type', 'text/plain')
|
|
677
|
+
*
|
|
678
|
+
* // Append multiple headers using the append option (e.g. Vary)
|
|
679
|
+
* c.header('Vary', 'Accept-Encoding', { append: true })
|
|
680
|
+
* c.header('Vary', 'User-Agent', { append: true })
|
|
681
|
+
*
|
|
682
|
+
* return c.body('Thank you for coming')
|
|
683
|
+
* })
|
|
684
|
+
* ```
|
|
685
|
+
*/
|
|
686
|
+
header = (name, value, options) => {
|
|
687
|
+
this.finalized && !this.#res.bodyUsed && (this.#res = createResponseInstance(this.#res.body, this.#res));
|
|
688
|
+
let headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
689
|
+
value === void 0 ? headers.delete(name) : options?.append ? headers.append(name, value) : headers.set(name, value);
|
|
690
|
+
};
|
|
691
|
+
status = (status) => {
|
|
692
|
+
this.#status = status;
|
|
693
|
+
};
|
|
694
|
+
/**
|
|
695
|
+
* `.set()` can set the value specified by the key.
|
|
696
|
+
*
|
|
697
|
+
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* ```ts
|
|
701
|
+
* app.use('*', async (c, next) => {
|
|
702
|
+
* c.set('message', 'Hono is hot!!')
|
|
703
|
+
* await next()
|
|
704
|
+
* })
|
|
705
|
+
* ```
|
|
706
|
+
*/
|
|
707
|
+
set = (key, value) => {
|
|
708
|
+
this.#var ??= /* @__PURE__ */ new Map(), this.#var.set(key, value);
|
|
709
|
+
};
|
|
710
|
+
/**
|
|
711
|
+
* `.get()` can use the value specified by the key.
|
|
712
|
+
*
|
|
713
|
+
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
714
|
+
*
|
|
715
|
+
* @example
|
|
716
|
+
* ```ts
|
|
717
|
+
* app.get('/', (c) => {
|
|
718
|
+
* const message = c.get('message')
|
|
719
|
+
* return c.text(`The message is "${message}"`)
|
|
720
|
+
* })
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
get = (key) => this.#var ? this.#var.get(key) : void 0;
|
|
724
|
+
/**
|
|
725
|
+
* `.var` can access the value of a variable.
|
|
726
|
+
*
|
|
727
|
+
* @see {@link https://hono.dev/docs/api/context#var}
|
|
728
|
+
*
|
|
729
|
+
* @example
|
|
730
|
+
* ```ts
|
|
731
|
+
* const result = c.var.client.oneMethod()
|
|
732
|
+
* ```
|
|
733
|
+
*/
|
|
734
|
+
get var() {
|
|
735
|
+
return this.#var ? Object.fromEntries(this.#var) : {};
|
|
736
|
+
}
|
|
737
|
+
#newResponse(data, arg, headers) {
|
|
738
|
+
let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
|
|
739
|
+
if (typeof arg == "object" && arg.headers) {
|
|
740
|
+
responseHeaders ??= new Headers();
|
|
741
|
+
for (let [key, value] of new Headers(arg.headers)) key === "set-cookie" ? responseHeaders.append(key, value) : responseHeaders.set(key, value);
|
|
742
|
+
}
|
|
743
|
+
if (headers) {
|
|
744
|
+
if (!responseHeaders) {
|
|
745
|
+
let count = 0;
|
|
746
|
+
for (let k in headers) if (++count > 1 || typeof headers[k] != "string") {
|
|
747
|
+
responseHeaders = new Headers();
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
if (responseHeaders) for (let k in headers) {
|
|
752
|
+
let v = headers[k];
|
|
753
|
+
if (typeof v == "string") responseHeaders.set(k, v);
|
|
754
|
+
else {
|
|
755
|
+
responseHeaders.delete(k);
|
|
756
|
+
for (let v2 of v) responseHeaders.append(k, v2);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
let status = typeof arg == "number" ? arg : arg?.status ?? this.#status;
|
|
761
|
+
return createResponseInstance(data, {
|
|
762
|
+
status,
|
|
763
|
+
headers: responseHeaders ?? headers
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
newResponse = (...args) => this.#newResponse(...args);
|
|
767
|
+
/**
|
|
768
|
+
* `.body()` can return the HTTP response.
|
|
769
|
+
* You can set headers with `.header()` and set HTTP status code with `.status`.
|
|
770
|
+
* This can also be set in `.text()`, `.json()` and so on.
|
|
771
|
+
*
|
|
772
|
+
* @see {@link https://hono.dev/docs/api/context#body}
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* ```ts
|
|
776
|
+
* app.get('/welcome', (c) => {
|
|
777
|
+
* // Set headers
|
|
778
|
+
* c.header('X-Message', 'Hello!')
|
|
779
|
+
* c.header('Content-Type', 'text/plain')
|
|
780
|
+
* // Set HTTP status code
|
|
781
|
+
* c.status(201)
|
|
782
|
+
*
|
|
783
|
+
* // Return the response body
|
|
784
|
+
* return c.body('Thank you for coming')
|
|
785
|
+
* })
|
|
786
|
+
* ```
|
|
787
|
+
*/
|
|
788
|
+
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
789
|
+
/**
|
|
790
|
+
* `.text()` can render text as `Content-Type:text/plain`.
|
|
791
|
+
*
|
|
792
|
+
* @see {@link https://hono.dev/docs/api/context#text}
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```ts
|
|
796
|
+
* app.get('/say', (c) => {
|
|
797
|
+
* return c.text('Hello!')
|
|
798
|
+
* })
|
|
799
|
+
* ```
|
|
800
|
+
*/
|
|
801
|
+
text = (text, arg, headers) => !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(text, arg, setDefaultContentType(TEXT_PLAIN, headers));
|
|
802
|
+
/**
|
|
803
|
+
* `.json()` can render JSON as `Content-Type:application/json`.
|
|
804
|
+
*
|
|
805
|
+
* @see {@link https://hono.dev/docs/api/context#json}
|
|
806
|
+
*
|
|
807
|
+
* @example
|
|
808
|
+
* ```ts
|
|
809
|
+
* app.get('/api', (c) => {
|
|
810
|
+
* return c.json({ message: 'Hello!' })
|
|
811
|
+
* })
|
|
812
|
+
* ```
|
|
813
|
+
*/
|
|
814
|
+
json = (object, arg, headers) => this.#newResponse(JSON.stringify(object), arg, setDefaultContentType("application/json", headers));
|
|
815
|
+
html = (html, arg, headers) => {
|
|
816
|
+
let res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
817
|
+
return typeof html == "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, !1, {}).then(res) : res(html);
|
|
818
|
+
};
|
|
819
|
+
/**
|
|
820
|
+
* `.redirect()` can Redirect, default status code is 302.
|
|
821
|
+
*
|
|
822
|
+
* @see {@link https://hono.dev/docs/api/context#redirect}
|
|
823
|
+
*
|
|
824
|
+
* @example
|
|
825
|
+
* ```ts
|
|
826
|
+
* app.get('/redirect', (c) => {
|
|
827
|
+
* return c.redirect('/')
|
|
828
|
+
* })
|
|
829
|
+
* app.get('/redirect-permanently', (c) => {
|
|
830
|
+
* return c.redirect('/', 301)
|
|
831
|
+
* })
|
|
832
|
+
* ```
|
|
833
|
+
*/
|
|
834
|
+
redirect = (location, status) => {
|
|
835
|
+
let locationString = String(location);
|
|
836
|
+
return this.header("Location", /[^\x00-\xFF]/.test(locationString) ? encodeURI(locationString) : locationString), this.newResponse(null, status ?? 302);
|
|
837
|
+
};
|
|
838
|
+
/**
|
|
839
|
+
* `.notFound()` can return the Not Found Response.
|
|
840
|
+
*
|
|
841
|
+
* @see {@link https://hono.dev/docs/api/context#notfound}
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
* ```ts
|
|
845
|
+
* app.get('/notfound', (c) => {
|
|
846
|
+
* return c.notFound()
|
|
847
|
+
* })
|
|
848
|
+
* ```
|
|
849
|
+
*/
|
|
850
|
+
notFound = () => (this.#notFoundHandler ??= () => createResponseInstance(), this.#notFoundHandler(this));
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/router.js
|
|
854
|
+
var METHODS = [
|
|
855
|
+
"get",
|
|
856
|
+
"post",
|
|
857
|
+
"put",
|
|
858
|
+
"delete",
|
|
859
|
+
"options",
|
|
860
|
+
"patch",
|
|
861
|
+
"query"
|
|
862
|
+
];
|
|
863
|
+
var UnsupportedPathError = class extends Error {
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/utils/constants.js
|
|
867
|
+
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
868
|
+
|
|
869
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/utils/mount.js
|
|
870
|
+
var getPathPrefixLength = (c, pathPrefix, routePath) => {
|
|
871
|
+
if (!/[:*]/.test(pathPrefix)) return pathPrefix.length;
|
|
872
|
+
let path = c.req.path, matchResult = c.req[GET_MATCH_RESULT], paramNames = /* @__PURE__ */ new Set(), length = 0;
|
|
873
|
+
for (let part of splitRoutingPath(pathPrefix)) {
|
|
874
|
+
let pattern = getPattern(part);
|
|
875
|
+
if (pattern && pattern !== "*") {
|
|
876
|
+
let name = pattern[1];
|
|
877
|
+
if (paramNames.has(name)) throw new Error(`mount(): Duplicate path parameter "${name}" in "${routePath}".`);
|
|
878
|
+
paramNames.add(name);
|
|
879
|
+
}
|
|
880
|
+
if (pattern && pattern !== "*" && pattern[2] !== !0) {
|
|
881
|
+
let value = matchResult.length === 2 ? matchResult[1][matchResult[0][c.req.routeIndex][1][pattern[1]]] : matchResult[0][c.req.routeIndex][1][pattern[1]];
|
|
882
|
+
length += value.length + 1;
|
|
883
|
+
} else if (pattern || part.endsWith("*")) {
|
|
884
|
+
let end = path.indexOf("/", length + 1);
|
|
885
|
+
length = end === -1 ? path.length : end;
|
|
886
|
+
} else length += part.length + 1;
|
|
887
|
+
}
|
|
888
|
+
return length;
|
|
889
|
+
}, createMountedRequest = (c, pathPrefix, routePath) => {
|
|
890
|
+
if (/[^/]\*$/.test(routePath)) throw new Error(`mount(): Wildcard must follow "/" in "${routePath}".`);
|
|
891
|
+
let url = new URL(c.req.raw.url);
|
|
892
|
+
return url.pathname = stripPathPrefix(url.pathname, c.req.path, getPathPrefixLength(c, pathPrefix, routePath)), new Request(url, c.req.raw);
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/hono-base.js
|
|
896
|
+
var notFoundHandler = (c) => c.text("404 Not Found", 404), errorHandler = (err, c) => {
|
|
897
|
+
if ("getResponse" in err) {
|
|
898
|
+
let res = err.getResponse();
|
|
899
|
+
return c.newResponse(res.body, res);
|
|
900
|
+
}
|
|
901
|
+
return console.error(err), c.text("Internal Server Error", 500);
|
|
902
|
+
}, Hono = class Hono2 {
|
|
903
|
+
get;
|
|
904
|
+
post;
|
|
905
|
+
put;
|
|
906
|
+
delete;
|
|
907
|
+
options;
|
|
908
|
+
patch;
|
|
909
|
+
query;
|
|
910
|
+
all;
|
|
911
|
+
on;
|
|
912
|
+
use;
|
|
913
|
+
router;
|
|
914
|
+
getPath;
|
|
915
|
+
_basePath = "/";
|
|
916
|
+
#path = "/";
|
|
917
|
+
routes = [];
|
|
918
|
+
constructor(options = {}) {
|
|
919
|
+
[...METHODS, "all"].forEach((method) => {
|
|
920
|
+
this[method] = (args1, ...args) => {
|
|
921
|
+
let methodName = method.toUpperCase();
|
|
922
|
+
return typeof args1 == "string" ? this.#path = args1 : this.#addRoute(methodName, this.#path, args1), args.forEach((handler) => {
|
|
923
|
+
this.#addRoute(methodName, this.#path, handler);
|
|
924
|
+
}), this;
|
|
925
|
+
};
|
|
926
|
+
}), this.on = (method, path, ...handlers) => {
|
|
927
|
+
for (let p of [path].flat()) {
|
|
928
|
+
this.#path = p;
|
|
929
|
+
for (let m of [method].flat()) {
|
|
930
|
+
let methodName = m.toUpperCase();
|
|
931
|
+
for (let handler of handlers) this.#addRoute(methodName, this.#path, handler);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
return this;
|
|
935
|
+
}, this.use = (arg1, ...handlers) => (typeof arg1 == "string" ? this.#path = arg1 : (this.#path = "*", handlers.unshift(arg1)), handlers.forEach((handler) => {
|
|
936
|
+
this.#addRoute("ALL", this.#path, handler);
|
|
937
|
+
}), this);
|
|
938
|
+
let { strict, ...optionsWithoutStrict } = options;
|
|
939
|
+
Object.assign(this, optionsWithoutStrict), this.getPath = strict ?? !0 ? options.getPath ?? getPath : getPathNoStrict;
|
|
940
|
+
}
|
|
941
|
+
#clone() {
|
|
942
|
+
let clone = new Hono2({
|
|
943
|
+
router: this.router,
|
|
944
|
+
getPath: this.getPath
|
|
945
|
+
});
|
|
946
|
+
return clone.errorHandler = this.errorHandler, clone.#notFoundHandler = this.#notFoundHandler, clone.routes = this.routes, clone;
|
|
947
|
+
}
|
|
948
|
+
#notFoundHandler = notFoundHandler;
|
|
949
|
+
errorHandler = errorHandler;
|
|
950
|
+
/**
|
|
951
|
+
* `.route()` allows grouping other Hono instance in routes.
|
|
952
|
+
*
|
|
953
|
+
* @see {@link https://hono.dev/docs/api/routing#grouping}
|
|
954
|
+
*
|
|
955
|
+
* @param {string} path - base Path
|
|
956
|
+
* @param {Hono} app - other Hono instance
|
|
957
|
+
* @returns {Hono} routed Hono instance
|
|
958
|
+
*
|
|
959
|
+
* @example
|
|
960
|
+
* ```ts
|
|
961
|
+
* const app = new Hono()
|
|
962
|
+
* const app2 = new Hono()
|
|
963
|
+
*
|
|
964
|
+
* app2.get("/user", (c) => c.text("user"))
|
|
965
|
+
* app.route("/api", app2) // GET /api/user
|
|
966
|
+
* ```
|
|
967
|
+
*/
|
|
968
|
+
route(path, app2) {
|
|
969
|
+
let subApp = this.basePath(path);
|
|
970
|
+
return app2.routes.map((r) => {
|
|
971
|
+
let handler;
|
|
972
|
+
app2.errorHandler === errorHandler ? handler = r.handler : (handler = async (c, next) => (await compose([], app2.errorHandler)(c, () => r.handler(c, next))).res, handler[COMPOSED_HANDLER] = r.handler), subApp.#addRoute(r.method, r.path, handler, r.basePath);
|
|
973
|
+
}), this;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* `.basePath()` allows base paths to be specified.
|
|
977
|
+
*
|
|
978
|
+
* @see {@link https://hono.dev/docs/api/routing#base-path}
|
|
979
|
+
*
|
|
980
|
+
* @param {string} path - base Path
|
|
981
|
+
* @returns {Hono} changed Hono instance
|
|
982
|
+
*
|
|
983
|
+
* @example
|
|
984
|
+
* ```ts
|
|
985
|
+
* const api = new Hono().basePath('/api')
|
|
986
|
+
* ```
|
|
987
|
+
*/
|
|
988
|
+
basePath(path) {
|
|
989
|
+
let subApp = this.#clone();
|
|
990
|
+
return subApp._basePath = mergePath(this._basePath, path), subApp;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* `.onError()` handles an error and returns a customized Response.
|
|
994
|
+
*
|
|
995
|
+
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
|
996
|
+
*
|
|
997
|
+
* @param {ErrorHandler} handler - request Handler for error
|
|
998
|
+
* @returns {Hono} changed Hono instance
|
|
999
|
+
*
|
|
1000
|
+
* @example
|
|
1001
|
+
* ```ts
|
|
1002
|
+
* app.onError((err, c) => {
|
|
1003
|
+
* console.error(`${err}`)
|
|
1004
|
+
* return c.text('Custom Error Message', 500)
|
|
1005
|
+
* })
|
|
1006
|
+
* ```
|
|
1007
|
+
*/
|
|
1008
|
+
onError = (handler) => (this.errorHandler = handler, this);
|
|
1009
|
+
/**
|
|
1010
|
+
* `.notFound()` allows you to customize a Not Found Response.
|
|
1011
|
+
*
|
|
1012
|
+
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
1013
|
+
*
|
|
1014
|
+
* @param {NotFoundHandler} handler - request handler for not-found
|
|
1015
|
+
* @returns {Hono} changed Hono instance
|
|
1016
|
+
*
|
|
1017
|
+
* @example
|
|
1018
|
+
* ```ts
|
|
1019
|
+
* app.notFound((c) => {
|
|
1020
|
+
* return c.text('Custom 404 Message', 404)
|
|
1021
|
+
* })
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
1024
|
+
notFound = (handler) => (this.#notFoundHandler = handler, this);
|
|
1025
|
+
/**
|
|
1026
|
+
* `.mount()` allows you to mount applications built with other frameworks into your Hono application.
|
|
1027
|
+
*
|
|
1028
|
+
* @deprecated Use `mount()` from `hono/mount` instead. `.mount()` will be removed in v5.
|
|
1029
|
+
*
|
|
1030
|
+
* @see {@link https://hono.dev/docs/api/hono#mount}
|
|
1031
|
+
*
|
|
1032
|
+
* @param {string} path - base Path
|
|
1033
|
+
* @param {Function} applicationHandler - other Request Handler
|
|
1034
|
+
* @param {MountOptions} [options] - options of `.mount()`
|
|
1035
|
+
* @returns {Hono} mounted Hono instance
|
|
1036
|
+
*
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```ts
|
|
1039
|
+
* import { Router as IttyRouter } from 'itty-router'
|
|
1040
|
+
* import { Hono } from 'hono'
|
|
1041
|
+
* // Create itty-router application
|
|
1042
|
+
* const ittyRouter = IttyRouter()
|
|
1043
|
+
* // GET /itty-router/hello
|
|
1044
|
+
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
1045
|
+
*
|
|
1046
|
+
* const app = new Hono()
|
|
1047
|
+
* app.mount('/itty-router', ittyRouter.handle)
|
|
1048
|
+
* ```
|
|
1049
|
+
*
|
|
1050
|
+
* @example
|
|
1051
|
+
* ```ts
|
|
1052
|
+
* const app = new Hono()
|
|
1053
|
+
* // Send the request to another application without modification.
|
|
1054
|
+
* app.mount('/app', anotherApp, {
|
|
1055
|
+
* replaceRequest: (req) => req,
|
|
1056
|
+
* })
|
|
1057
|
+
* ```
|
|
1058
|
+
*/
|
|
1059
|
+
mount(path, applicationHandler, options) {
|
|
1060
|
+
let replaceRequest, optionHandler;
|
|
1061
|
+
options && (typeof options == "function" ? optionHandler = options : (optionHandler = options.optionHandler, options.replaceRequest === !1 ? replaceRequest = (request) => request : replaceRequest = options.replaceRequest));
|
|
1062
|
+
let getOptions = optionHandler ? (c) => {
|
|
1063
|
+
let options2 = optionHandler(c);
|
|
1064
|
+
return Array.isArray(options2) ? options2 : [options2];
|
|
1065
|
+
} : (c) => {
|
|
1066
|
+
let executionContext;
|
|
1067
|
+
try {
|
|
1068
|
+
executionContext = c.executionCtx;
|
|
1069
|
+
} catch {
|
|
1070
|
+
}
|
|
1071
|
+
return [c.env, executionContext];
|
|
1072
|
+
}, mergedPath = mergePath(this._basePath, path), defaultReplaceRequest = (c) => createMountedRequest(c, mergedPath.replace(/\/$/, ""), mergePath(mergedPath, "*")), handler = async (c, next) => {
|
|
1073
|
+
let res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
|
|
1074
|
+
if (res) return res;
|
|
1075
|
+
await next();
|
|
1076
|
+
};
|
|
1077
|
+
return this.#addRoute("ALL", mergePath(path, "*"), handler), this;
|
|
1078
|
+
}
|
|
1079
|
+
#addRoute(method, path, handler, baseRoutePath) {
|
|
1080
|
+
path = mergePath(this._basePath, path);
|
|
1081
|
+
let r = {
|
|
1082
|
+
basePath: baseRoutePath !== void 0 ? mergePath(this._basePath, baseRoutePath) : this._basePath,
|
|
1083
|
+
path,
|
|
1084
|
+
method,
|
|
1085
|
+
handler
|
|
1086
|
+
};
|
|
1087
|
+
this.router.add(method, path, [handler, r]), this.routes.push(r);
|
|
1088
|
+
}
|
|
1089
|
+
#handleError(err, c) {
|
|
1090
|
+
if (err instanceof Error) return this.errorHandler(err, c);
|
|
1091
|
+
throw err;
|
|
1092
|
+
}
|
|
1093
|
+
#dispatch(request, executionCtx, env, method) {
|
|
1094
|
+
if (method === "HEAD") return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
1095
|
+
let path = this.getPath(request, { env }), matchResult = this.router.match(method, path), c = new Context(request, {
|
|
1096
|
+
path,
|
|
1097
|
+
matchResult,
|
|
1098
|
+
env,
|
|
1099
|
+
executionCtx,
|
|
1100
|
+
notFoundHandler: this.#notFoundHandler
|
|
1101
|
+
});
|
|
1102
|
+
if (matchResult[0].length === 1) {
|
|
1103
|
+
let res;
|
|
1104
|
+
try {
|
|
1105
|
+
res = matchResult[0][0][0][0](c, async () => {
|
|
1106
|
+
c.res = await this.#notFoundHandler(c);
|
|
1107
|
+
});
|
|
1108
|
+
} catch (err) {
|
|
1109
|
+
return this.#handleError(err, c);
|
|
1110
|
+
}
|
|
1111
|
+
return res instanceof Promise ? res.then((resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
|
1112
|
+
}
|
|
1113
|
+
let composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
1114
|
+
return (async () => {
|
|
1115
|
+
try {
|
|
1116
|
+
let context = await composed(c);
|
|
1117
|
+
if (!context.finalized) throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
1118
|
+
return context.res;
|
|
1119
|
+
} catch (err) {
|
|
1120
|
+
return this.#handleError(err, c);
|
|
1121
|
+
}
|
|
1122
|
+
})();
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* `.fetch()` will be entry point of your app.
|
|
1126
|
+
*
|
|
1127
|
+
* @see {@link https://hono.dev/docs/api/hono#fetch}
|
|
1128
|
+
*
|
|
1129
|
+
* @param {Request} request - request Object of request
|
|
1130
|
+
* @param {Env} env - env Object
|
|
1131
|
+
* @param {ExecutionContext} executionCtx - context of execution
|
|
1132
|
+
* @returns {Response | Promise<Response>} response of request
|
|
1133
|
+
*
|
|
1134
|
+
*/
|
|
1135
|
+
fetch = (request, ...rest) => this.#dispatch(request, rest[1], rest[0], request.method);
|
|
1136
|
+
/**
|
|
1137
|
+
* `.request()` is a useful method for testing.
|
|
1138
|
+
* You can pass a URL or pathname to send a GET request.
|
|
1139
|
+
* app will return a Response object.
|
|
1140
|
+
* ```ts
|
|
1141
|
+
* test('GET /hello is ok', async () => {
|
|
1142
|
+
* const res = await app.request('/hello')
|
|
1143
|
+
* expect(res.status).toBe(200)
|
|
1144
|
+
* })
|
|
1145
|
+
* ```
|
|
1146
|
+
* @see https://hono.dev/docs/api/hono#request
|
|
1147
|
+
*/
|
|
1148
|
+
request = (input, requestInit, Env, executionCtx) => input instanceof Request ? this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx) : (input = input.toString(), this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx));
|
|
1149
|
+
/**
|
|
1150
|
+
* `.fire()` automatically adds a global fetch event listener.
|
|
1151
|
+
* This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
|
|
1152
|
+
* @deprecated
|
|
1153
|
+
* Use `fire` from `hono/service-worker` instead.
|
|
1154
|
+
* ```ts
|
|
1155
|
+
* import { Hono } from 'hono'
|
|
1156
|
+
* import { fire } from 'hono/service-worker'
|
|
1157
|
+
*
|
|
1158
|
+
* const app = new Hono()
|
|
1159
|
+
* // ...
|
|
1160
|
+
* fire(app)
|
|
1161
|
+
* ```
|
|
1162
|
+
* @see https://hono.dev/docs/api/hono#fire
|
|
1163
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
|
1164
|
+
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
|
|
1165
|
+
*/
|
|
1166
|
+
fire = () => {
|
|
1167
|
+
addEventListener("fetch", (event) => {
|
|
1168
|
+
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
1169
|
+
});
|
|
1170
|
+
};
|
|
1171
|
+
};
|
|
1172
|
+
|
|
1173
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/router/pattern-router/router.js
|
|
1174
|
+
var emptyParams = /* @__PURE__ */ Object.create(null), PatternRouter = class {
|
|
1175
|
+
name = "PatternRouter";
|
|
1176
|
+
#routes = [];
|
|
1177
|
+
add(method, path, handler) {
|
|
1178
|
+
let suffix = path.endsWith("/*") ? "(?:$|/)" : path.endsWith("*") ? "" : "/?$";
|
|
1179
|
+
path = path.replace(/\*$/, ""), path.at(-1) === "?" && (path = path.slice(0, -1), this.add(method, path.replace(/\/[^/]+$/, ""), handler));
|
|
1180
|
+
let parts = (path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+/g) || []).map((part) => {
|
|
1181
|
+
let match = part.match(/^\/:([^{]+)(?:{(.*)})?/);
|
|
1182
|
+
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.replace(/[.\\+*[^\]$()]/g, "\\$&");
|
|
1183
|
+
});
|
|
1184
|
+
try {
|
|
1185
|
+
this.#routes.push([
|
|
1186
|
+
new RegExp(`^${parts.join("")}${suffix}`),
|
|
1187
|
+
method,
|
|
1188
|
+
handler
|
|
1189
|
+
]);
|
|
1190
|
+
} catch {
|
|
1191
|
+
throw new UnsupportedPathError();
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
match(method, path) {
|
|
1195
|
+
let handlers = [];
|
|
1196
|
+
for (let i = 0, len = this.#routes.length; i < len; i++) {
|
|
1197
|
+
let [pattern, routeMethod, handler] = this.#routes[i];
|
|
1198
|
+
if (routeMethod === method || routeMethod === "ALL") {
|
|
1199
|
+
let match = pattern.exec(path);
|
|
1200
|
+
match && handlers.push([handler, match.groups || emptyParams]);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
return [handlers];
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
|
+
// ../../node_modules/.pnpm/hono@4.13.16/node_modules/hono/dist/preset/tiny.js
|
|
1208
|
+
var Hono3 = class extends Hono {
|
|
1209
|
+
constructor(options = {}) {
|
|
1210
|
+
super(options), this.router = new PatternRouter();
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
// src/workers/core/constants.ts
|
|
1215
|
+
var CorePaths = {
|
|
1216
|
+
/** Magic proxy used by getPlatformProxy */
|
|
1217
|
+
PLATFORM_PROXY: "/cdn-cgi/local/platform-proxy",
|
|
1218
|
+
/** Trigger scheduled event handlers */
|
|
1219
|
+
SCHEDULED: "/cdn-cgi/local/scheduled",
|
|
1220
|
+
/** Trigger email event handlers */
|
|
1221
|
+
EMAIL: "/cdn-cgi/local/email",
|
|
1222
|
+
/** Local explorer UI and API */
|
|
1223
|
+
EXPLORER: "/cdn-cgi/local/explorer",
|
|
1224
|
+
/** Stream video serving endpoint (outside /cdn-cgi/ for tunnel access) */
|
|
1225
|
+
STREAM_VIDEO: "/__cf_local/stream",
|
|
1226
|
+
/** Local image delivery endpoint (outside /cdn-cgi/ for tunnel access) */
|
|
1227
|
+
IMAGE_DELIVERY: "/__cf_local/imagedelivery",
|
|
1228
|
+
/** Local Direct Creator Upload completion endpoint (outside /cdn-cgi/ for tunnel access) */
|
|
1229
|
+
IMAGE_UPLOAD: "/__cf_local/imageupload",
|
|
1230
|
+
/** Public R2 bucket object serving endpoint */
|
|
1231
|
+
R2_PUBLIC: "/cdn-cgi/local/r2/public",
|
|
1232
|
+
/** S3-compatible API endpoint for local R2 buckets */
|
|
1233
|
+
R2_S3: "/cdn-cgi/local/r2/s3"
|
|
1234
|
+
};
|
|
1235
|
+
|
|
1236
|
+
// src/workers/r2/serve.worker.ts
|
|
1237
|
+
var RANGE_HEADER = /^bytes=(?:(\d+)-(\d+)?|-(\d+))$/;
|
|
1238
|
+
function parseRangeHeader(header) {
|
|
1239
|
+
let match = RANGE_HEADER.exec(header);
|
|
1240
|
+
if (match === null)
|
|
1241
|
+
return { error: "malformed" };
|
|
1242
|
+
let [, start, end, suffix] = match;
|
|
1243
|
+
return start === void 0 ? Number(suffix) === 0 ? { error: "unsatisfiable" } : {} : end !== void 0 && Number(start) > Number(end) ? { error: "inverted" } : { start: Number(start) };
|
|
1244
|
+
}
|
|
1245
|
+
function objectHeaders(object) {
|
|
1246
|
+
let headers = new Headers();
|
|
1247
|
+
return object.writeHttpMetadata(headers), headers.has("Content-Type") || headers.set("Content-Type", "application/octet-stream"), headers.set("ETag", object.httpEtag), headers.set("Last-Modified", object.uploaded.toUTCString()), headers.set("Accept-Ranges", "bytes"), headers;
|
|
1248
|
+
}
|
|
1249
|
+
async function serveR2Object(request, bucket, key, handlers, parsedRange) {
|
|
1250
|
+
let rangeHeader = request.headers.get("Range"), hasRange = rangeHeader !== null, object = await bucket.get(key, {
|
|
1251
|
+
onlyIf: request.headers,
|
|
1252
|
+
range: hasRange ? request.headers : void 0
|
|
1253
|
+
});
|
|
1254
|
+
if (object === null)
|
|
1255
|
+
return handlers.notFound();
|
|
1256
|
+
let headers = objectHeaders(object);
|
|
1257
|
+
if (handlers.decorateHeaders?.(object, headers), !("body" in object)) {
|
|
1258
|
+
let preconditions;
|
|
1259
|
+
for (let name of ["If-Match", "If-Unmodified-Since"]) {
|
|
1260
|
+
let value = request.headers.get(name);
|
|
1261
|
+
value !== null && (preconditions ??= new Headers(), preconditions.set(name, value));
|
|
1262
|
+
}
|
|
1263
|
+
if (preconditions !== void 0) {
|
|
1264
|
+
let recheck = await bucket.get(key, { onlyIf: preconditions });
|
|
1265
|
+
if (recheck === null)
|
|
1266
|
+
return handlers.notFound();
|
|
1267
|
+
if (!("body" in recheck))
|
|
1268
|
+
return handlers.preconditionFailed();
|
|
1269
|
+
recheck.body.cancel();
|
|
1270
|
+
}
|
|
1271
|
+
return new Response(null, { status: 304, headers });
|
|
1272
|
+
}
|
|
1273
|
+
let body = request.method === "HEAD" ? null : object.body;
|
|
1274
|
+
body === null && object.body.cancel();
|
|
1275
|
+
let range = object.range;
|
|
1276
|
+
if (hasRange && range !== void 0) {
|
|
1277
|
+
if (handlers.invalidRange !== void 0) {
|
|
1278
|
+
let parsed = parsedRange ?? parseRangeHeader(rangeHeader);
|
|
1279
|
+
if (!("error" in parsed) && (object.size === 0 || parsed.start !== void 0 && parsed.start >= object.size))
|
|
1280
|
+
return body !== null && body.cancel(), handlers.invalidRange();
|
|
1281
|
+
}
|
|
1282
|
+
let normalized = {
|
|
1283
|
+
...range
|
|
1284
|
+
}, offset, length;
|
|
1285
|
+
return normalized.suffix !== void 0 ? (length = Math.min(normalized.suffix, object.size), offset = object.size - length) : (offset = normalized.offset ?? 0, length = normalized.length ?? object.size - offset), headers.set(
|
|
1286
|
+
"Content-Range",
|
|
1287
|
+
`bytes ${offset}-${offset + length - 1}/${object.size}`
|
|
1288
|
+
), headers.set("Content-Length", `${length}`), new Response(body, { status: 206, headers });
|
|
1289
|
+
}
|
|
1290
|
+
return headers.set("Content-Length", `${object.size}`), new Response(body, { headers });
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
// src/workers/r2/public.worker.ts
|
|
1294
|
+
var app = new Hono3().basePath(CorePaths.R2_PUBLIC);
|
|
1295
|
+
app.use(
|
|
1296
|
+
cors({ origin: "*", allowMethods: ["GET", "HEAD"], exposeHeaders: ["*"] })
|
|
1297
|
+
);
|
|
1298
|
+
app.on(["GET", "HEAD"], "/:bucketId/:key{.+}", async (c) => {
|
|
1299
|
+
let bucketId = c.req.param("bucketId"), key = c.req.param("key"), bucket = c.env[bucketId];
|
|
1300
|
+
if (bucket === void 0)
|
|
1301
|
+
return c.notFound();
|
|
1302
|
+
let rangeHeader = c.req.header("Range"), parsedRange = rangeHeader === void 0 ? void 0 : parseRangeHeader(rangeHeader);
|
|
1303
|
+
return parsedRange !== void 0 && "error" in parsedRange ? c.body(null, parsedRange.error === "unsatisfiable" ? 416 : 400) : serveR2Object(
|
|
1304
|
+
c.req.raw,
|
|
1305
|
+
bucket,
|
|
1306
|
+
key,
|
|
1307
|
+
{
|
|
1308
|
+
notFound: () => c.notFound(),
|
|
1309
|
+
preconditionFailed: () => c.body(null, 412),
|
|
1310
|
+
invalidRange: () => c.body(null, 416)
|
|
1311
|
+
},
|
|
1312
|
+
parsedRange
|
|
1313
|
+
);
|
|
1314
|
+
});
|
|
1315
|
+
app.all("/:bucketId/:key{.+}", (c) => c.body(null, 401));
|
|
1316
|
+
var public_worker_default = app;
|
|
1317
|
+
export {
|
|
1318
|
+
public_worker_default as default
|
|
1319
|
+
};
|