Step-by-step guides for integrating G8KEPR with your existing tech stack. From Express.js to Django, we've got you covered with production-ready examples.
Integrate G8KEPR as a reverse proxy in front of your Express application:
# docker-compose.yml
version: '3.8'
services:
gatekeeper:
image: g8kepr/gateway:latest
ports:
- "3000:3000"
environment:
BACKEND_URL: http://app:4000
JWT_SECRET: your_jwt_secret_here
RATE_LIMIT: 1000
depends_on:
- app
app:
build: .
expose:
- "4000"
environment:
NODE_ENV: production
PORT: 4000// server.js
const express = require('express');
const app = express();
// Trust proxy headers from G8KEPR
app.set('trust proxy', true);
// Access G8KEPR headers
app.use((req, res, next) => {
const requestId = req.header('X-G8KEPR-Request-ID');
const userId = req.header('X-G8KEPR-User-ID');
console.log(`Request ${requestId} from user ${userId}`);
next();
});
app.get('/api/products', (req, res) => {
res.json({ products: [...] });
});
app.listen(4000, () => {
console.log('Server running on port 4000');
});# Start both services
docker-compose up -d
# Verify G8KEPR is proxying requests
curl http://localhost:3000/api/products
# Check logs
docker-compose logs -f gatekeeperIntegrate G8KEPR with FastAPI applications using middleware:
from fastapi import FastAPI, Request
from fastapi.middleware.trustedhost import TrustedHostMiddleware
app = FastAPI()
# Trust G8KEPR proxy
app.add_middleware(
TrustedHostMiddleware,
allowed_hosts=["gatekeeper", "localhost"]
)
@app.middleware("http")
async def add_request_context(request: Request, call_next):
# Extract G8KEPR headers
request_id = request.headers.get("X-G8KEPR-Request-ID")
user_id = request.headers.get("X-G8KEPR-User-ID")
security_mode = request.headers.get("X-G8KEPR-Security-Mode")
# Add to request state
request.state.request_id = request_id
request.state.user_id = user_id
response = await call_next(request)
return response
@app.get("/api/products")
async def get_products(request: Request):
# Access user from G8KEPR
user_id = request.state.user_id
return {"products": [...], "user_id": user_id}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)version: '3.8'
services:
gatekeeper:
image: g8kepr/gateway:latest
ports:
- "8000:8000"
environment:
BACKEND_URL: http://api:8000
ENABLE_THREAT_DETECTION: "true"
MONITOR_MODE: "false"
depends_on:
- api
api:
build: .
expose:
- "8000"
command: uvicorn app.main:app --host 0.0.0.0Add G8KEPR middleware to your Django project:
# middleware/gatekeeper.py
class GatekeeperMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
# Extract G8KEPR headers
request.request_id = request.META.get('HTTP_X_G8KEPR_REQUEST_ID')
request.user_id = request.META.get('HTTP_X_G8KEPR_USER_ID')
request.security_mode = request.META.get('HTTP_X_G8KEPR_SECURITY_MODE')
# Log security events
if request.META.get('HTTP_X_G8KEPR_THREAT_DETECTED'):
threat_type = request.META.get('HTTP_X_G8KEPR_THREAT_TYPE')
logger.warning(f"Threat detected: {threat_type}")
response = self.get_response(request)
return response# settings.py
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'middleware.gatekeeper.GatekeeperMiddleware', # Add this
'django.contrib.sessions.middleware.SessionMiddleware',
# ... other middleware
]
# Trust G8KEPR proxy
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Add G8KEPR IPs to allowed hosts
ALLOWED_HOSTS = ['gatekeeper', 'localhost', 'your-domain.com']Configure Rails to work behind G8KEPR reverse proxy:
class GatekeeperHeaders
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
# Extract G8KEPR headers
request_id = request.get_header('HTTP_X_G8KEPR_REQUEST_ID')
user_id = request.get_header('HTTP_X_G8KEPR_USER_ID')
# Add to thread-local storage
Thread.current[:request_id] = request_id
Thread.current[:user_id] = user_id
@app.call(env)
end
end# config/application.rb
module YourApp
class Application < Rails::Application
# Trust G8KEPR proxy
config.middleware.use GatekeeperHeaders
# Configure trusted proxies
config.action_dispatch.trusted_proxies = [
'10.0.0.0/8', # Your internal network
'172.16.0.0/12'
]
end
endAdd G8KEPR filter to Spring Boot application:
@Component
public class GatekeeperFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(
HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain
) throws ServletException, IOException {
// Extract G8KEPR headers
String requestId = request.getHeader("X-G8KEPR-Request-ID");
String userId = request.getHeader("X-G8KEPR-User-ID");
String securityMode = request.getHeader("X-G8KEPR-Security-Mode");
// Add to MDC for logging
MDC.put("requestId", requestId);
MDC.put("userId", userId);
try {
filterChain.doFilter(request, response);
} finally {
MDC.clear();
}
}
}server:
port: 8080
forward-headers-strategy: framework # Trust proxy headers
spring:
application:
name: your-api
logging:
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} [%X{requestId}] %logger{36} - %msg%n"Create middleware for Gin to extract G8KEPR headers:
package main
import (
"github.com/gin-gonic/gin"
"log"
)
// GatekeeperMiddleware extracts G8KEPR headers
func GatekeeperMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
requestID := c.GetHeader("X-G8KEPR-Request-ID")
userID := c.GetHeader("X-G8KEPR-User-ID")
securityMode := c.GetHeader("X-G8KEPR-Security-Mode")
// Add to context
c.Set("requestID", requestID)
c.Set("userID", userID)
// Log
log.Printf("[%s] User %s - %s %s",
requestID, userID, c.Request.Method, c.Request.URL.Path)
c.Next()
}
}
func main() {
r := gin.Default()
// Use G8KEPR middleware
r.Use(GatekeeperMiddleware())
// Configure trusted proxies
r.SetTrustedProxies([]string{"10.0.0.0/8"})
r.GET("/api/products", func(c *gin.Context) {
userID := c.GetString("userID")
c.JSON(200, gin.H{
"products": []string{"item1", "item2"},
"user_id": userID,
})
})
r.Run(":8080")
}Get the full 45-page guide with additional frameworks (PHP Laravel, .NET, Rust) and advanced configurations
Our team can help you integrate G8KEPR with your specific tech stack in under 30 minutes