跳转到内容

Plugin Overview

此内容尚不支持你的语言。

The plugin system is MiniGateway’s extensibility mechanism. Plugins can modify requests, responses, and implement custom logic.

Plugins execute in two phases:

Runs before the request is proxied to the target:

interface RequestPlugin {
name: string;
onRequest?: (ctx: PluginContext) => Promise<void | Response>;
}

Use cases:

  • Authentication and authorization
  • Rate limiting
  • Request validation
  • Header/body transformation
  • Request logging

Runs after receiving the backend response:

interface ResponsePlugin {
name: string;
onResponse?: (ctx: ResponseContext) => Promise<void>;
}

Use cases:

  • Response transformation
  • Caching
  • Logging
  • Error handling

Both phases receive rich context:

interface PluginContext {
// Original request
request: Request;
// Matching entities
route: Route;
service: Service;
upstream: Upstream;
target?: Target;
consumer?: Consumer;
// Path parameters
params: Record<string, string>;
// Shared state (persist across phases)
state: Record<string, unknown>;
// Storage access
storage: StorageContext;
}