inndx/
GitHub

Middleware

The fetch middleware that transforms requests and responses.

Middleware transforms a request before the client sends it, or a response after it returns. A job lists middleware under config.fetcher.middleware, applied in order. This page catalogs the available kinds and their parameters.

How middleware is configured

Each entry in config.fetcher.middleware is an object with a kind and a params object. Middleware is applied in the order listed. Some kinds act on the outgoing request, and some can act on either the request or the response, selected with an on field.

config:
  fetcher:
    middleware:
      - kind: set_language
        params:
          languages:
            - [en-US, 1.0]

mutate_path

Rewrites the request path when it matches a path pattern. The paths map keys are path patterns and the values are the replacement paths.

FieldTypeRequiredDefaultDescription
pathsmap of path pattern to stringyesnoneEach matching path pattern is rewritten to its mapped replacement path.
middleware:
  - kind: mutate_path
    params:
      paths:
        /old/*: /new

mutate_method

Changes the HTTP method for requests whose path matches a pattern.

FieldTypeRequiredDefaultDescription
pathsmap of path pattern to methodyesnoneEach matching path pattern uses its mapped HTTP method.
middleware:
  - kind: mutate_method
    params:
      paths:
        /search/*: POST

mutate_headers

Adds or overrides headers on the request or the response.

FieldTypeRequiredDefaultDescription
onrequest or responseyesnoneWhether the headers are applied to the request or the response.
headerslist of name and value pairsyesnoneThe headers to set, each as a two-element [name, value] list.
middleware:
  - kind: mutate_headers
    params:
      on: request
      headers:
        - [X-Api-Key, <your-api-key>]
        - [Accept, application/json]

mutate_json_body

Transforms a JSON request or response body using an expression. The expression is written in CEL (Common Expression Language).

FieldTypeRequiredDefaultDescription
onrequest or responseyesnoneWhether the transform applies to the request or the response body.
expressionstringyesnoneA CEL expression that produces the new JSON body.
middleware:
  - kind: mutate_json_body
    params:
      on: response
      expression: "body.data"

set_language

Sets the request's preferred languages, which become the Accept-Language header. Each entry pairs a language tag with a quality weight between 0 and 1.

FieldTypeRequiredDefaultDescription
languageslist of tag and weight pairsyesnoneThe preferred languages, each as a two-element [tag, weight] list.
middleware:
  - kind: set_language
    params:
      languages:
        - [en-US, 1.0]
        - [en, 0.8]

Search docs

Search the Self-host documentation