Files
SnowLuma/.pnpm-store/v11/files/c7/d394fe2644472f9143f4ea1f64e4065fdd12b19b596b785845fe552e9d07c949c56a1e503bd964d0f7ec4b1ab279085ff3fac29a4cb1fb8e5c5a590d87e383
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

59 lines
1.5 KiB
Plaintext

import { isDynamicRoute } from "./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 (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
export { SSG_CONTEXT, SSG_DISABLED_RESPONSE, X_HONO_DISABLE_SSG_HEADER_KEY, disableSSG, isSSGContext, onlySSG, ssgParams };