Skip to content

Middleware Ecosystem Comparison

Comprehensive comparison of Farrow framework with Express.js and Koa.js middleware ecosystems.

Mainstream Middleware Ecosystem Comparison

Feature CategoryExpress.jsKoa.jsFarrow FrameworkRecommendedStatus
Authentication✅ passport, express-jwt, express-session✅ koa-passport, koa-jwt, koa-session✅ farrow-auth-session, farrow-auth-jwtApplication LayerCommunity solutions available
File Upload✅ multer, express-fileupload✅ multer, koa-multer, @koa/multer🚧 PlannedApplication LayerGap, needs development
Data Validation✅ joi, express-validator, yup✅ joi, koa-validate, yup✅ farrow-schemaApplication LayerFarrow Built-in Advantage
Routing System✅ express.Router✅ koa-router, @koa/router✅ farrow-httpApplication LayerFarrow Built-in Advantage
Error Handling✅ Callback-style error handling✅ Exception catching + onerror✅ Functional error handlingApplication LayerFarrow Architecture Advantage
Request Parsing✅ body-parser, express.json✅ koa-bodyparser, koa-body✅ farrow-http built-inApplication LayerFarrow Built-in Advantage
CORS Handling✅ cors✅ @koa/cors✅ farrow-corsNginx PriorityOfficial package available, but Nginx recommended
Response Compression✅ compression✅ koa-compress❌ No development plansNginx PriorityRecommended gzip on;
Static Files✅ express.static✅ koa-static, koa-static-cache✅ Built-in serve methodNginx PriorityFarrow has built-in support, but Nginx recommended
Cache Control✅ express-cache-controller✅ koa-cache-control❌ No development plansNginx PriorityRecommended expires directive
Rate Limiting✅ express-rate-limit✅ koa-ratelimit❌ No development plansNginx PriorityRecommended limit_req
Security Protection✅ helmet, express-security✅ koa-helmet✅ farrow-helmet (but Nginx recommended)Nginx PriorityCommunity solution exists, but add_header recommended
Access Logging✅ morgan, winston✅ koa-logger, koa-pino-logger🔄 ComplementaryLayered ApproachGateway + Application dual logging
Reverse Proxy✅ http-proxy-middleware✅ koa-proxies❌ No development plansNginx PriorityRecommended proxy_pass

Nginx/OpenResty and Application Layer Division

Layered Architecture Principles

In modern Web application architecture, many traditional "middleware" functions are better handled at the gateway layer (Nginx/OpenResty), allowing the application layer to focus on business logic.

CapabilityNginx/OpenResty ImplementationExpress/Koa MiddlewareFarrow RecommendationConclusion & Advantages
Response Compressiongzip on; + Brotli modulescompression, koa-compress❌ No development plansNginx Priority: Better performance, supports pre-compressed files
Static Assetslocation + root/aliasexpress.static, koa-static❌ No development plansNginx Priority: Higher throughput, better caching
Cache Controlexpires, etag on;Various cache middleware❌ No development plansNginx Priority: Unified cache strategy, reduces application burden
Rate Limitinglimit_req, limit_connexpress-rate-limit etc❌ No development plansNginx Priority: Edge interception, protects backend resources
CORS Handlingadd_header directivescors, @koa/cors✅ farrow-cors (but Nginx recommended)Nginx Priority: Reduces application layer configuration complexity
Security Headersadd_header (CSP, HSTS etc)helmet series❌ No development plansNginx Priority: Unified security policy management
Reverse Proxyproxy_pass + load balancinghttp-proxy-middleware❌ No development plansNginx Priority: Comprehensive protocol support, excellent connection management
Access Loggingaccess_log + custom formatmorgan, koa-logger🔄 ComplementaryLayered Logging: Gateway logs requests, application logs business

Nginx Configuration Example

nginx
# nginx.conf
server {
    listen 80;
    server_name api.example.com;
    
    # Compression configuration
    gzip on;
    gzip_types text/plain application/json application/javascript text/css;
    
    # Security headers
    add_header X-Frame-Options DENY always;
    add_header X-Content-Type-Options nosniff always;
    add_header X-XSS-Protection "1; mode=block" always;
    
    # CORS handling
    add_header Access-Control-Allow-Origin "https://app.example.com" always;
    add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
    
    # Rate limiting configuration
    limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
    limit_req zone=api burst=20 nodelay;
    
    # Static assets
    location /static/ {
        root /var/www;
        expires 1y;
        add_header Cache-Control "public, immutable";
    }
    
    # Reverse proxy to Farrow application
    location /api/ {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Farrow Application Focuses on Business

typescript
// Farrow application only cares about core business logic
const app = Http()

// Authentication middleware
const authenticate = async (req: RequestInfo, next: Next) => {
  const token = req.headers?.authorization?.replace('Bearer ', '')
  if (!token) {
    return Response.status(401).json({ error: 'No token' })
  }
  
  try {
    const user = jwt.verify(token, secret)
    AuthContext.set(user)
    return next(req)
  } catch (error) {
    return Response.status(401).json({ error: 'Invalid token' })
  }
}

// User API (built-in type safety)
app.post('/users', {
  body: UserCreateSchema  // Schema validation
}).use(authenticate)
  .use((req) => {
    const user = createUser(req.body)
    return Response.status(201).json(user)
  })

// No need to handle: compression, CORS, rate limiting, static files etc.
// These are all handled by Nginx layer

This is a third-party Farrow documentation site | Built with ❤️ and TypeScript