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

    Type Alias DurableObjectMiddleware<P, D>

    DurableObjectMiddleware: (
        ctx: DurableObjectContext<P, D>,
        state: DurableObjectState,
        next: () => Promise<Response>,
    ) => Promise<Response>

    Middleware function type for DurableObjectRouter. Receives (ctx, state, next) where ctx contains per-request data and state is the DurableObjectState.

    Type Parameters

    • P = Params

      Route parameters type

    • D = Record<string, any>

      Data type for middleware-set data

    Type Declaration

      • (
            ctx: DurableObjectContext<P, D>,
            state: DurableObjectState,
            next: () => Promise<Response>,
        ): Promise<Response>
      • Parameters

        Returns Promise<Response>

    const authMiddleware: DurableObjectMiddleware<{ id: string }, { user: User }> =
    async (ctx, state, next) => {
    const session = await state.storage.get(`session:${token}`);
    ctx.data.user = session.user;
    return next();
    };