Files
SnowLuma/.pnpm-store/v11/files/31/299f8437317f00a1dfc03addd381fb76cbb156b050384cc5acff191484dca184da67c1811c3535eefe8661022db2793828b756ba8a69584c0794c9011f3986
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

48 lines
1.6 KiB
Plaintext

import { Env, MiddlewareHandler } from "../../types.js";
import { Context } from "../../context.js";
import { Hono } from "../../hono.js";
//#region src/middleware/method-not-allowed/index.d.ts
type MethodNotAllowedHandler<E extends Env> = (c: Context<E>, allowedMethods: string[]) => Response | Promise<Response>;
type MethodNotAllowedOptions<E extends Env> = {
app: Hono<E, any, any>;
onMethodNotAllowed?: MethodNotAllowedHandler<E>;
};
/**
* Method Not Allowed Middleware for Hono.
*
* Returns a `405 Method Not Allowed` response with an `Allow` header when the request path
* matches a registered route but the request method is not supported.
*
* @param {MethodNotAllowedOptions} options - The options for the middleware.
* @param {Hono} options.app - The Hono instance used by the application.
* @param {MethodNotAllowedHandler} [options.onMethodNotAllowed] - Generates the response, including its `Allow` header.
* @returns {MiddlewareHandler} The middleware handler function.
*
* @example
* ```ts
* const app = new Hono()
*
* app.use(methodNotAllowed({ app }))
*
* app.get('/hello', (c) => c.text('Hello!'))
* app.post('/hello', (c) => c.text('Posted!'))
*
* // PUT /hello -> 405 Method Not Allowed
* // Allow: GET, HEAD, POST
* ```
*
* @example
* ```ts
* app.use(
* methodNotAllowed({
* app,
* onMethodNotAllowed: (c, methods) =>
* c.json({ error: 'Method Not Allowed' }, 405, { Allow: methods.join(', ') }),
* })
* )
* ```
*/
export declare const methodNotAllowed: <E extends Env = Env>(options: MethodNotAllowedOptions<E>) => MiddlewareHandler<E>;
//#endregion
export {};