Files
SnowLuma/.pnpm-store/v11/files/08/8f4dcd901321b3bf3acd15d37e791343bc1a393286802075c425dc03e025476b845255c181a0cb36b3d8f247ef168152dbd8f5dbb143166748d921161a8ada
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

66 lines
1.7 KiB
Plaintext

Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_helper_ssg_utils = require("./utils.js");
//#region src/helper/ssg/middleware.ts
const SSG_CONTEXT = "HONO_SSG_CONTEXT";
const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
/**
* @deprecated
* Use `X_HONO_DISABLE_SSG_HEADER_KEY` instead.
* This constant will be removed in the next minor version.
*/
const SSG_DISABLED_RESPONSE = (() => {
try {
return new Response("SSG is disabled", {
status: 404,
headers: { [X_HONO_DISABLE_SSG_HEADER_KEY]: "true" }
});
} catch {
return null;
}
})();
/**
* Define SSG Route
*/
const ssgParams = (params) => async (c, next) => {
if (require_helper_ssg_utils.isDynamicRoute(c.req.path)) {
c.req.raw.ssgParams = Array.isArray(params) ? params : await params(c);
return c.notFound();
}
await next();
};
/**
* @experimental
* `isSSGContext` is an experimental feature.
* The API might be changed.
*/
const isSSGContext = (c) => !!c.env?.[SSG_CONTEXT];
/**
* @experimental
* `disableSSG` is an experimental feature.
* The API might be changed.
*/
const disableSSG = () => async function disableSSG(c, next) {
if (isSSGContext(c)) {
c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true");
return c.notFound();
}
await next();
};
/**
* @experimental
* `onlySSG` is an experimental feature.
* The API might be changed.
*/
const onlySSG = () => async function onlySSG(c, next) {
if (!isSSGContext(c)) return c.notFound();
await next();
};
//#endregion
exports.SSG_CONTEXT = SSG_CONTEXT;
exports.SSG_DISABLED_RESPONSE = SSG_DISABLED_RESPONSE;
exports.X_HONO_DISABLE_SSG_HEADER_KEY = X_HONO_DISABLE_SSG_HEADER_KEY;
exports.disableSSG = disableSSG;
exports.isSSGContext = isSSGContext;
exports.onlySSG = onlySSG;
exports.ssgParams = ssgParams;