Skip to main content
skill CX Codex

edgeone-makers-middleware — Claude Code skill: features and install

The edgeone-makers-middleware Claude Code skill helps build request middleware for EdgeOne Makers. It covers redirects, URL rewrites, access checks, and edge routing.

MIT 248 installs ★ 1,839 updated 2026-11-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add TencentEdgeOne/edgeone-makers-tools --skill edgeone-makers-middleware -a claude-code
Open on GitHub

What edgeone-makers-middleware does

The skill helps create middleware that intercepts requests in EdgeOne Makers. It can redirect traffic, change the requested path while keeping the client-facing URL, check authorization, and add headers. It also covers routing by geolocation and A/B tests.

Middleware receives a context object with next, redirect, and rewrite methods; project files use the names middleware.js or middleware.ts. The handler runs on every route by default, while config.matcher narrows its scope. This platform format is not for Next.js, Nuxt, or other framework projects; those should use their framework’s own middleware.

What it helps with

  • redirect requests from an old URL to a new one
  • rewrite a request path without changing the URL shown to the client
  • protect API routes with a token check
  • add IP and country-code headers to requests
  • route requests by location or A/B variant

Example prompts for the agent

  • Set up middleware.js to redirect /old-page to /new-page.
  • Add an Authorization check for /api/:path* and /admin/:path*.
  • Create an A/B test for /landing using /landing-a and /landing-b.

How to install edgeone-makers-middleware

1Skills CLI (Vercel)

npx skills add TencentEdgeOne/edgeone-makers-tools --skill edgeone-makers-middleware -a claude-code

2Manually: put the files in place

~/.claude/skills/makers-middleware/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/makers-middleware/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about edgeone-makers-middleware

How do I install edgeone-makers-middleware in Claude Code?

Run npx skills add TencentEdgeOne/edgeone-makers-tools --skill edgeone-makers-middleware -a claude-code. The skill file is placed at ~/.claude/skills/makers-middleware/SKILL.md.

What does edgeone-makers-middleware do?

It helps write EdgeOne Makers middleware for redirects, request rewrites, authorization checks, header changes, and routing.

Can I use edgeone-makers-middleware with Next.js?

No. Next.js and other framework projects should use the framework’s built-in middleware. This format is for projects without a framework or for static projects.

Source text

SKILL.md · MIT
---
name: edgeone-makers-middleware
description: >-
  Edge middleware for EdgeOne Makers — request interception, redirects, rewrites,
  auth guards, A/B testing, and header injection at the edge (V8 runtime).
pathPatterns:
  - middleware.js
  - middleware.ts
validate:
  - pattern: "NextRequest|NextResponse|next/server"
    message: "Framework projects must use the framework's own middleware. This platform format takes a context object with next/redirect/rewrite — not NextRequest/NextResponse."
metadata:
  author: edgeone
  version: "1.0.0"
---

# Middleware

Lightweight request interception running at the edge (V8 runtime). Use for redirects, rewrites, auth guards, A/B testing, and header injection.

> ⚠️ **Framework projects (Next.js, Nuxt, etc.)**: Do NOT use this platform middleware format. Use the framework's built-in middleware instead (e.g. Next.js `middleware.ts` with `NextRequest`/`NextResponse`). The patterns below are for non-framework or pure static projects only.

## Basic middleware

File: `middleware.js` (project root)

```javascript
export function middleware(context) {
  const { request, next, redirect, rewrite } = context;

  // Pass through — no modification
  return next();
}
```

## Context API

| Property | Type | Description |
|----------|------|-------------|
| `request` | `Request` | Current request object |
| `next(options?)` | `Function` | Continue to origin; optionally modify headers |
| `redirect(url, status?)` | `Function` | Redirect (default 307) |
| `rewrite(url)` | `Function` | Rewrite request path (transparent to client) |
| `geo` | `GeoProperties` | Client geolocation |
| `clientIp` | `string` | Client IP address |

## Route matching

By default middleware runs on ALL routes. Use `config.matcher` to limit scope:

```javascript
// Only run on /api/* routes
export const config = {
  matcher: ['/api/:path*'],
};

export function middleware(context) {
  // Auth check for API routes only
  const token = context.request.headers.get('Authorization');
  if (!token) {
    return new Response('Unauthorized', { status: 401 });
  }
  return context.next();
}
```

**Matcher patterns:**

```javascript
// Single path
export const config = { matcher: '/about' };

// Multiple paths
export const config = { matcher: ['/api/:path*', '/admin/:path*'] };

// Regex
export const config = { matcher: ['/api/.*', '^/user/\\d+$'] };
```

## Common patterns

### URL Redirect

```javascript
export function middleware(context) {
  const url = new URL(context.request.url);

  if (url.pathname === '/old-page') {
    return context.redirect('/new-page', 301);
  }
  return context.next();
}
```

### URL Rewrite (transparent proxy)

```javascript
export function middleware(context) {
  const url = new URL(context.request.url);

  if (url.pathname.startsWith('/blog')) {
    return context.rewrite('/content' + url.pathname);
  }
  return context.next();
}
```

### Add request headers

```javascript
export function middleware(context) {
  return context.next({
    headers: {
      'x-request-id': crypto.randomUUID(),
      'x-client-ip': context.clientIp,
      'x-country': context.geo.countryCodeAlpha2,
    },
  });
}
```

### Auth guard

```javascript
export const config = {
  matcher: ['/api/:path*', '/admin/:path*'],
};

export function middleware(context) {
  const token = context.request.headers.get('Authorization');
  if (!token || !token.startsWith('Bearer ')) {
    return new Response(JSON.stringify({ error: 'Unauthorized' }), {
      status: 401,
      headers: { 'Content-Type': 'application/json' },
    });
  }
  return context.next();
}
```

### Geo-based routing

```javascript
export function middleware(context) {
  const country = context.geo.countryCodeAlpha2;

  if (country === 'CN') {
    return context.rewrite('/zh' + new URL(context.request.url).pathname);
  }
  return context.next();
}
```

### A/B Testing

```javascript
export function middleware(context) {
  const url = new URL(context.request.url);

  if (url.pathname === '/landing') {
    const variant = Math.random() < 0.5 ? '/landing-a' : '/landing-b';
    return context.rewrite(variant);
  }
  return context.next();
}
```

### Direct JSON response

```javascript
export function middleware(context) {
  const url = new URL(context.request.url);

  if (url.pathname === '/api/health') {
    return new Response(JSON.stringify({ status: 'ok', timestamp: Date.now() }), {
      headers: { 'Content-Type': 'application/json' },
    });
  }
  return context.next();
}
```

## GeoProperties

Available on `context.geo`:

| Property | Type | Example |
|----------|------|---------|
| `countryName` | string | Singapore |
| `countryCodeAlpha2` | string | SG |
| `countryCodeAlpha3` | string | SGP |
| `regionName` | string | — |
| `cityName` | string | Singapore |
| `latitude` | number | 1.29027 |
| `longitude` | number | 103.851959 |
| `asn` | number | 132203 |

© edgeone · MIT · TencentEdgeOne/edgeone-makers-tools

Similar skills

All skills for Backend and APIs →

From the same set11

The whole set →
edgeone-makers-cloud-functions edgeone-makers-cloud-functions — a skill for Claude Code and other platforms adds Node.js, Go, and Python runtimes for serverless functions. Runs when building backend logic, server-side APIs, or Express and Koa patterns. CX Codex +1 299installs edgeone-makers-deploy edgeone-makers-deploy — a skill for Claude Code deploys frontend and full-stack projects to Tencent EdgeOne Makers. Activates on release requests, preview deployments, or anonymous publishing without an account. CX Codex +1 285installs edgeone-makers-agents edgeone-makers-agents — a Claude Code skill for building and reviewing AI agent endpoints across five frameworks on EdgeOne Makers. Used when setting up LangGraph routes or configuring SSE streaming responses. CX Codex +1 260installs edgeone-makers-edge-functions This Claude Code skill covers EdgeOne Makers Edge Functions. The agent uses it when editing files under edge-functions/** or functions/**. CX Codex +1 253installs edgeone-makers-storage edgeone-makers-storage — a skill for Claude Code that configures storage on EdgeOne Makers. Sets up KV for Edge Functions and structures dynamic project data using Blob storage in Cloud Functions. CX Codex +1 250installs edgeone-makers-env-adaption The edgeone-makers-env-adaption Claude Code skill adapts EdgeOne Makers workflows to restricted environments. It activates in WorkBuddy or sandboxed IDEs where CLI prompts stall or network access goes through a proxy. CX Codex +1 249installs edgeone-makers-recipes edgeone-makers-recipes — a skill for Claude Code that generates project structures and templates for EdgeOne Makers apps. CX Codex +1 249installs edgeone-makers-migration edgeone-makers-migration — a skill for Claude Code that migrates existing AI agent projects to the EdgeOne Makers platform. It automates structural conversion, API adaptation, and platform capability injection. CX Codex +1 152installs

Project sponsors

Companies that keep this analytics open