Options
All
  • Public
  • Public/Protected
  • All
Menu

External module Middleware

Index

Type aliases

ResponseModifierResult

ResponseModifierResult: Promise<undefined | void | Response> | undefined | void | Response

Variables

Const httpsUpgrader

httpsUpgrader: function = requestModifier(httpsRedirect)

Redirects http requests to https in production.

In development, this only logs a message

Type declaration

Const responseHeaders

responseHeaders: function = responseModifier(addResponseHeaders)

Middleware to set headers on responses

param
param

Type declaration

Functions

autoWebp

  • Automatically encodes images as webp for supported clients. This would apply to requests with 'image/webp' in the accept header and 'image/jpeg' or 'image/png' in the response type from origin.

    Example:

    import { origin } from "./src/backends";
    import { autoWebp } from "./src/middleware/auto-webp";
    
    const backend = origin({
     origin: "https://fly.io/",
     headers: {host: "fly.io"}
    })
    
    const images = autoWebp(backend);
    
    fly.http.respondWith(images);

    Parameters

    Returns FetchFunction

httpCache

  • Cache HTTP responses with cache-control headers.

    Basic example:

    import httpCache from "./src/middleware/http-cache";
    import backends from "./src/backends";
    
    const glitch = backends.glitch("fly-example");
    
    const origin = httpCache(glitch, { overrideMaxAge: 3600 });
    
    fly.http.respondWith(origin);

    Parameters

    Returns FetchFunction

httpsRedirect

  • httpsRedirect(req: Request, options?: RedirectOptions): undefined | Response
  • Checks request protocol, returns Redirect response if request is http.

    In development, this function just logs a message to the console.

    Parameters

    • req: Request

      The request to check

    • Optional options: RedirectOptions

      Options for the resulting redirect

    Returns undefined | Response

requestModifier

responseModifier

  • A convenience function for building middleware that only operates on a response.

    Type parameters

    • J

    Parameters

    • fn: function
        • (resp: Response, options: J): Promise<Response> | Response
        • Parameters

          • resp: Response
          • options: J

          Returns Promise<Response> | Response

    Returns FetchGeneratorWithOptions<J>

webpAllowed

  • webpAllowed(req: Request): boolean

Generated using TypeDoc