Skip to main content

Plugins & Middlewares

This page covers only the configuration syntax for attaching plugins and middlewares to a flow. To write a custom plugin or middleware, see Plugin & Middleware Development; for what ships with Aastro out of the box, see Built-in Plugins & Middlewares.

Plugins​

plugins:
- name: snakeify
source: builtin
- name: myplugin
source: file
path: /etc/aastro/plugins/
config:
key: value
FieldTypeRequiredDefaultDescription
namestringtrue-Plugin identifier
sourcestringtrue-builtin (included with Aastro) or file (custom .so)
pathstringif file-Directory containing the .so file
configmapfalse{}Plugin-specific configuration passed at initialization

Plugins run in two phases:

  • Request phase - before the upstream call. Can read and modify the request context and headers
  • Response phase - after the response is built. Can modify response headers and body

Plugin execution order within each phase matches the order defined in configuration.

warning

Plugins are loaded as Go shared objects (.so). They must be compiled with the exact same Go version as the gateway binary. A version mismatch causes a panic at startup. Plugins within a single flow are deduplicated by name - a plugin listed twice is loaded only once.

Middlewares​

middlewares:
- name: recoverer
source: builtin
- name: auth
source: builtin
config:
alg: HS256
issuer: https://auth.example.com
audience: api
hmac_secret: "base64secret"
- name: logger
source: builtin

Middlewares use the same name, source, path, and config fields as plugins. They wrap the entire flow handler as standard http.Handler middleware and execute in the order defined - the first middleware in the list is the outermost wrapper.

Middlewares wrap the HTTP handler and run for every request regardless of upstream results. Plugins are invoked explicitly at defined phases in the request lifecycle. Use middlewares for cross-cutting concerns (authentication, logging, recovery), and plugins for data transformation.

Built-in middlewares:

NameDescription
recovererRecovers from panics and returns 500 instead of crashing
loggerStructured request logging with latency and status
authJWT validation (HS256, RS256 with static key or JWKS)
compressorResponse compression (gzip, deflate, br)
corsCross-Origin Resource Sharing headers