@whi/cf-routing - v0.7.0
    Preparing search index...

    Type Alias Middleware<E, P, D>

    Middleware: (
        ctx: Context<E, P, D>,
        next: () => Promise<Response>,
    ) => Promise<Response>

    Middleware function type with next() pattern.

    Middleware can:

    • Run code before calling next() (pre-processing)
    • Run code after calling next() (post-processing)
    • Short-circuit by returning a Response without calling next()
    • Throw HttpError to return an error response

    Type Parameters

    • E = Env

      Environment type

    • P = Params

      Route parameters type

    • D = Record<string, any>

      Data type for middleware-set data

    Type Declaration

      • (ctx: Context<E, P, D>, next: () => Promise<Response>): Promise<Response>
      • Parameters

        • ctx: Context<E, P, D>
        • next: () => Promise<Response>

        Returns Promise<Response>

    const timingMiddleware: Middleware = async (ctx, next) => {
    const start = Date.now();

    const response = await next();

    ctx.log.info(`Request took ${Date.now() - start}ms`);
    return response;
    };