liveBook · Manning

Middleware

As explained in Learn Docker in a Month of Lunches, Second Edition

A Traefik middleware is a request-processing component that modifies or validates traffic before forwarding it to a service.

A Traefik middleware changes or checks an HTTP request after a router matches it and before Traefik forwards it to the service. It can rewrite paths, modify headers, or enforce authentication. section 20.4

Use middleware when a routed request needs an adjustment before reaching its upstream container:

  • Strip an API path prefix when the application expects the path without that prefix. section 20.4
  • Change request headers or enforce authentication before forwarding traffic. section 20.4

Expose an API beneath a shared domain

Route requests for the image gallery domain with an /api prefix, then use middleware to remove that prefix before forwarding the request to the API service. Verify both the website and API with curl. section 20.4

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Defines path, header, and authentication uses, then demonstrates path-prefix rewriting without detailing middleware labels.
Examples
Uses an image gallery API mounted under an /api path and verified with curl.
What it assumes
Assumes familiarity with Traefik entrypoints, routers, services, container labels, and Docker Compose routing.
What you can do after
Configure path rewriting for a routed container application and verify the resulting website and API requests.
How it connects
Connects middleware with reverse proxies, HTTP routers, services, request paths, headers, and authentication.

Also explained in

Compare how 10 books explain middleware →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.