docs: added plugins docs, updated cloudflare docs

This commit is contained in:
dswbx
2025-08-29 08:35:56 +02:00
parent 9436b8bac5
commit 1fdfcf02b8
7 changed files with 341 additions and 79 deletions
+22 -1
View File
@@ -23,13 +23,34 @@ import type { IEmailDriver, ICacheDriver } from "core/drivers";
import { Api, type ApiOptions } from "Api";
export type AppPluginConfig = {
/**
* The name of the plugin.
*/
name: string;
/**
* The schema of the plugin.
*/
schema?: () => MaybePromise<ReturnType<typeof prototypeEm> | void>;
/**
* Called before the app is built.
*/
beforeBuild?: () => MaybePromise<void>;
/**
* Called after the app is built.
*/
onBuilt?: () => MaybePromise<void>;
/**
* Called when the server is initialized.
*/
onServerInit?: (server: Hono<ServerEnv>) => MaybePromise<void>;
onFirstBoot?: () => MaybePromise<void>;
/**
* Called when the app is booted.
*/
onBoot?: () => MaybePromise<void>;
/**
* Called when the app is first booted.
*/
onFirstBoot?: () => MaybePromise<void>;
};
export type AppPlugin = (app: App) => AppPluginConfig;
+6 -2
View File
@@ -11,7 +11,7 @@ type BunEnv = Bun.Env;
export type BunBkndConfig<Env = BunEnv> = RuntimeBkndConfig<Env> & Omit<ServeOptions, "fetch">;
export async function createApp<Env = BunEnv>(
{ distPath, ...config }: BunBkndConfig<Env> = {},
{ distPath, serveStatic: _serveStatic, ...config }: BunBkndConfig<Env> = {},
args: Env = {} as Env,
opts?: RuntimeOptions,
) {
@@ -20,7 +20,11 @@ export async function createApp<Env = BunEnv>(
return await createRuntimeApp(
{
serveStatic: serveStatic({ root }),
serveStatic:
_serveStatic ??
serveStatic({
root,
}),
...config,
},
args ?? (process.env as Env),
+1 -1
View File
@@ -6,7 +6,7 @@ import { resolve } from "node:path";
* Vite plugin that provides Node.js filesystem access during development
* by injecting a polyfill into the SSR environment
*/
export function devFsPlugin({
export function devFsVitePlugin({
verbose = false,
configFile = "bknd.config.ts",
}: {
@@ -19,22 +19,41 @@ const schema = s.partialObject({
type ImageOptimizationSchema = s.Static<typeof schema>;
export type CloudflareImageOptimizationOptions = {
/**
* The url to access the image optimization plugin, defaults to `/api/plugin/image/optimize`
*/
accessUrl?: string;
/**
* The path to resolve the image from, defaults to `/api/media/file`
*/
resolvePath?: string;
/**
* Whether to explain the image optimization schema, defaults to `false`
*/
explain?: boolean;
/**
* The default options to use, defaults to `{}`
* @param: config
*/
defaultOptions?: ImageOptimizationSchema;
/**
* The fixed options to use, defaults to `{}`
*/
fixedOptions?: ImageOptimizationSchema;
/**
* The cache control to use, defaults to `public, max-age=31536000, immutable`
*/
cacheControl?: string;
};
export function cloudflareImageOptimization({
accessUrl = "/_plugin/image/optimize",
accessUrl = "/api/plugin/image/optimize",
resolvePath = "/api/media/file",
explain = false,
defaultOptions = {},
fixedOptions = {},
}: CloudflareImageOptimizationOptions = {}): AppPlugin {
const disallowedAccessUrls = ["/api", "/admin", "/_optimize"];
const disallowedAccessUrls = ["/api", "/admin", "/api/plugin"];
if (disallowedAccessUrls.includes(accessUrl) || accessUrl.length < 2) {
throw new Error(`Disallowed accessUrl: ${accessUrl}`);
}