Options
All
  • Public
  • Public/Protected
  • All
Menu

@polarpop/azure-middleware

Index

Functions

default

Type aliases

Context

Context<T>: AzureContext & { end: AzureContext["done"]; next: NextFunction<T> } & ExtraContext<T>

Added context for @azure/functions context

Type parameters

  • T = any

NextFunction

NextFunction<T>: (err?: Error | string | null, context?: Partial<Omit<Context<T>, "next" | "done" | "end">>) => Promise<any> | void

Type parameters

  • T

Type declaration

    • (err?: Error | string | null, context?: Partial<Omit<Context<T>, "next" | "done" | "end">>): Promise<any> | void
    • Type alias for context.next()

      example
      import azureMiddleware from '@polarpop/azure-middleware';
      import { HttpRequest } from '@azure/functions';

      const app = azureMiddleware<HttpRequest>();

      app.use((context, req) => {
      context.next(undefined, { id: req.body.id });
      });

      export default app.handler();

      Parameters

      • Optional err: Error | string | null

        Optional error from the middleware functions

      • Optional context: Partial<Omit<Context<T>, "next" | "done" | "end">>

        Added context to the AzureContext

      Returns Promise<any> | void

AzureFunction

AzureFunction<T, Ctx>: (context: Exclude<Ctx, "next">, ...args: T[]) => Promise<any> | void

Type parameters

Type declaration

    • (context: Exclude<Ctx, "next">, ...args: T[]): Promise<any> | void
    • Parameters

      • context: Exclude<Ctx, "next">
      • Rest ...args: T[]

      Returns Promise<any> | void

MiddlewareFunction

MiddlewareFunction<T, Ctx>: (context: Ctx, input: T, ...args: any[]) => Promise<void> | void

Type parameters

Type declaration

    • (context: Ctx, input: T, ...args: any[]): Promise<void> | void
    • Callback function for AzureMiddleware.use.

      example
      import azureMiddleware, { MiddlewareFunction, Context } from '@polarpop/azure-middleware';
      import { HttpRequest } from '@azure/functions';

      const app = azureMiddleware();

      const typedMiddleware: MiddlewareFunction<HttpRequest, Context<{ user: { id: string } }>> = (context, req) => {
      context.log.info(context.user.id);
      context.next();
      };

      app.use((context, req) => {
      context.user = {
      id: 'random user id'
      };

      context.next(undefined, context);
      });

      app.use(typedMiddleware); // will output the user id of `random user id`

      export default app.listen();

      Parameters

      • context: Ctx

        The azure function context or chained context.

      • input: T

        The input, defaults to any type, but can be defined here or within AzureMiddleware.constructor.

      • Rest ...args: any[]

        The extra args that come with some azure functions.

      Returns Promise<void> | void

Generated using TypeDoc