A simple gRPC plugin for Tyk Gateway written in Node.js.
- Pre-request middleware: Adds custom headers and logs requests
- Custom authentication: Simple token validation example
- Event handling: Handles auth failure events
cd grpc-plugin-node
npm install
# Or directly:
npm run dev
The server will start on port 5555 by default.
Update your Tyk configuration (tyk.conf
) to enable gRPC coprocess:
"coprocess_options": {
"enable_coprocess": true,
"coprocess_grpc_server": "tcp://localhost:5555"
}
Import the api definition into your Tyk Install:
api-definition.json
curl -i http://localhost:8080/grpc-test/get
Look for the X-Custom-Header: Processed-By-gRPC-Plugin
in the response.
curl -i http://localhost:8080/grpc-test/headers \
-H "Authorization: Bearer special-token"
This will add an additional X-Special-User: true
header.
- server.js: The main gRPC server that implements the Tyk Dispatcher service
- proto/: Contains Tyk's protocol buffer definitions
- api-definition.json: API definition containing the pre-defined plugin
The plugin intercepts requests at various stages:
- Pre-middleware: Runs before the request is proxied
- Auth middleware: Can validate tokens and create sessions
- Event handlers: React to events like authentication failures
Modify server.js
to add your own logic:
MyPreMiddleware()
: Add request preprocessing
GRPC_PORT
: Change the gRPC server port (default: 5555)