Customizable examples for extending the Cosmo Router with custom modules and middleware.
Router Documentation • Module Configuration
Get your custom Cosmo Router running in under 5 minutes! Choose your preferred approach below.
Each example is a self-contained router configuration with a custom module. You can copy the example directory to your own repository and start customizing it.
Example | Path | Documentation | Description |
---|---|---|---|
Complete Module | examples/complete/ |
📖 README | Advanced router customization with custom modules and middleware |
There are two way to produce a deployable artifact:
🐳 Docker Image (Recommended)
Build the image:
docker build \
--platform linux/amd64 \
--build-arg TARGETOS=linux \
--build-arg TARGETARCH=amd64 \
--build-arg VERSION=$(git describe --tags --always --dirty) \
--build-arg COMMIT=$(git rev-parse HEAD) \
--build-arg DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
-t myrouter:latest .
Multi-arch builds: The Dockerfile supports multiple architectures. For custom builds, set TARGETOS
and TARGETARCH
(e.g., darwin/arm64
for Mac M1).
Run the router:
docker run --name myrouter --rm -p 3002:3002 \
-e LISTEN_ADDR=0.0.0.0:3002 \
-e DEMO_MODE=true \
myrouter:latest
Visit localhost:3002 to see your router in action!
Go Binary (Requires Go 1.25+)
Requirements: Go 1.25+
Build & Run:
go mod download
go build -o router main.go && chmod +x router
./router
Visit localhost:3002 to see your router in action!
The router requires a graph api token to serve your supergraph. Follow the instructions in WunderGraph Cloud Onboarding to get your token.
You can upgrade the router in each example directory by following the instructions below.
- Get the commit SHA from releases page
- Navigate to your router directory (where
go.mod
exists) - Update dependencies:
cd examples/complete # your example directory go get github.com/wundergraph/cosmo/router@<commit-sha>
Note
Run go get
from the directory containing go.mod
Contributions are welcome! Please feel free to submit examples, improvements, and bug fixes.
Cosmo is licensed under the Apache License, Version 2.0.