• Product Introduction
  • Billing
    • Billing Overview
    • Package
      • Plan Comparison
      • Free Plan
      • Pro Plan
      • Commercial Plan
    • Purchase and Renewal Guide
    • Plan Consumption and Usage
    • Billing Rules
      • Resource Billing Description
      • MU Billing Overview
    • Overdue Payments and Refunds
      • Overdue Payments and Plan Expiration
      • Refund
    • Billing FAQs
  • Quick Start
    • Agent Development
    • Importing a Git Repository
    • Starting From a Template
    • Direct Upload
    • Start with AI
  • Framework Guide
    • Agent
    • Frontends
      • Vite
      • React
      • Vue
      • Hugo
      • Other Frameworks
    • Backends
    • Full-stack
      • Next.js
      • Nuxt
      • Astro
      • React Router
      • SvelteKit
      • TanStack Start
      • Vike
    • Custom 404 Page
  • Space Guide
    • Space Management
  • Project Guide
    • Project Management
    • edgeone.json
    • Configuring Cache
    • Building Output Configuration
    • Error Codes
  • Build Guide
  • Deployment Guide
    • Overview
    • Create Deploys
    • Manage Deploys
    • Deploy Button
    • Using Github Actions
    • Using Gitlab CI/CD
    • Using CNB Plugin
    • Using IDE PlugIn
    • Using CodeBuddy IDE
  • Domain Management
    • Overview
    • Custom Domain
    • HTTPS Configuration
      • Overview
      • Apply for Free Certificate
      • Using Managed SSL Certificate
    • Configure DNS CNAME Record
  • Observability
    • Overview
    • Metric Analysis
    • Log Analysis
  • Makers for Platforms
    • Platform and Multi-Tenancy
    • Vibe Coding Solution
    • Platform Request Middleware
    • Template Example
      • Vibe Coding General Template
      • Vibe Coding Platform Template
  • Functions
    • Overview
    • Edge Functions
    • Cloud Functions
      • Overview
      • Node.js
      • Python
      • Go
  • Agents
    • Overview
    • Quick Start
    • Conversation Management
    • Observability
    • Sandbox Tool
      • Overview
      • Using the Agent Framework
      • Sandbox Atomic API
      • Network Search Tool
    • Agent Authentication
  • Models
    • Overview
    • Models and Vendors
      • Overview
      • Using the Zhuque Model
      • Using the Jev Model
      • Using Vendor Keys
        • OpenAI
        • Anthropic
        • Google AI Studio
        • DeepSeek
        • MiniMax
        • Hunyuan
        • Zhipu
        • MoonShot AI
    • FAQs
  • Storage
    • Overview
    • KV
    • Blob
  • Middleware
  • AI-Native Development
    • Skills
    • MCP
    • Plugin
  • Copilot
    • Overview
    • Quick Start
  • API Token
  • EdgeOne CLI
  • Makers API
    • History
    • API Category
    • Making API Requests
      • Request Structure
      • Common Params
      • Signature v3
      • Signature
      • Responses
    • Project APIs
      • CreateProject
      • DeleteProject
      • DeleteProjectEnvs
      • DescribeEnvironments
      • DescribeProjectEnvs
      • DescribeProjects
      • ModifyProject
      • ModifyProjectEnvs
    • Deployment APIs
      • CreateDeployment
      • DescribeCosTempToken
      • DescribeDeploymentLog
      • DescribeDeployments
    • Domain Name APIs
      • CreateZoneCustomDomain
      • DeleteProjectCustomDomains
      • DescribeZoneCustomDomains
      • ModifyZoneCustomDomainEnv
    • Data Types
    • Error Codes
  • Makers SDK
    • Overview
    • Examples
      • Creating a Deployment
      • Deploying via the CLI
      • Project Management
    • Projects
      • Project Operations
      • Environment Variable
    • Deployment
    • Domain
  • Message Notification
  • Access Permission
  • Integration Guide
    • AI
      • Makers Models Integration
      • Large Models for Images Integration
    • Database
      • Supabase Integration
      • Pages KV Integration
    • Ecommerce
      • Shopify Integration
      • WooCommerce Integration
    • Payment
      • Stripe Integration
      • Integrating Paddle
    • CMS
      • WordPress Integration
      • Contentful Integration
      • Sanity Integration
      • Payload Integration
    • Authentication
      • Supabase Integration
      • Clerk Integration
    • IM
      • Overview
      • WeCom
      • Feishu
      • DingTalk
      • Telegram
      • slack
      • Discord
  • Best Practices
    • Adding an AI Chat Assistant to a Website
    • AI Dialogue Deployment: Deploy Project with One Sentence Using Skill
    • Building Agent Applications Quickly with Makers Agents
    • Building an Ecommerce Platform with Shopify
    • Building a SaaS Site Using Supabase and Stripe
    • Building a Company Brand Site Quickly
    • How to Quickly Build a Blog Site
    • Quick Launch via Login-Free Deployment in WorkBuddy
  • Migration Guides
    • Migrating from Vercel to EdgeOne Makers
    • Migrating from Cloudflare Pages to EdgeOne Makers
    • Migrating from Netlify to EdgeOne Makers
  • Troubleshooting
  • FAQs
  • Contact Us
  • Release Notes

Platform Request Middleware

When building a multi-project platform with Makers, you only need to connect one wildcard domain to assign subdomains to tenant projects. Makers automatically routes requests to the corresponding projects, eliminating the need to maintain this distribution logic yourself. The platform request middleware is bound to the wildcard domain and runs before requests enter a project. A single script can centrally handle authentication, traffic control, and other common logic for all projects under the domain, eliminating the need to repeat development in each project.


How to Configure

The middleware takes effect based on the wildcard domain and is uploaded as a single .js file. Configuration steps:
1. Contact us to connect a wildcard domain (for example, *.example.com) to the platform, and confirm that the wildcard domain has taken effect.
2. In the console, go to Settings > Platform and Multi-Tenancy, and upload the script in the Request Middleware column of the target wildcard domain.

It takes effect approximately 15 minutes after upload. Once it takes effect, all requests from projects under the domain pass through it first. Only one middleware is retained for the same wildcard domain, and uploading again replaces the current version. You can also update, download, or delete the existing script at the same entry.

Script Structure

The file can contain only one top-level declaration, which must be the following function. The parameter name must be context.
async function onRequest(context) {}
In addition:
You cannot write import or export, nor can you use dynamic import().
You cannot declare variables, functions, or other statements at the top level. Functions that need to be reused should be written inside onRequest.
You cannot introduce external dependencies or use Node.js APIs such as require, fs, and process.
The script is compiled according to ES2023 before execution. You can use the following Web APIs: Request, Response, URL, and Headers.

Configuration Constraints

It can only be configured for a wildcard domain that has already taken effect, and it takes effect approximately 15 minutes after configuration.
Each wildcard domain has only one request middleware, and uploading again replaces the current version.
Uploads or updates for the same wildcard domain must be at least 30 seconds apart.
Only .js files are accepted. The encoding must be UTF-8, and the file size must not exceed 1 MB.

context Parameter

The context received by onRequest has the following members:
Member
Description
request
The request that is currently entering the middleware can read the URL, method, request headers, and request body.
fetch(input, init?)
Obtain the response of the current project. For input, pass a Request object or a URL string.
init is an optional parameter and has the same meaning as RequestInit.
waitUntil(promise)
Register a Promise. After the response is returned, the runtime still waits for it to complete, and it does not change the response that has already been returned.
async function onRequest(context) {
const request = context.request;// Obtain the complete request object
const url = new URL(request.url);// Construct a URL object
const response = await context.fetch(request);// Fetch the request without returning it for now
const copy = response.clone();// Clone the request to test asynchronous waiting
context.waitUntil(copy.arrayBuffer());// Wait for asynchronous completion
return response;
}
In addition to the APIs mounted on the context, other JS runtime examples can also be used. For details, see Edge Functions.

Examples

API Access Control

Requests other than /api/ are forwarded to the project as-is. Requests to /api/ must include the agreed Authorization header. Otherwise, a 401 response is returned and the request does not go to the project.
async function onRequest(context) {
const request = context.request;
const url = new URL(request.url);
const platformToken = 'xxx';//Platform Token
if (!url.pathname.startsWith("/api/")) {
return context.fetch(request);
}

const token = request.headers.get("authorization");
if(token != platformToken){
return new Response(JSON.stringify({ code: 401, message: "unauthorized" }), {
status: 401,
headers: { "content-type": "application/json; charset=utf-8" },
});
}
return context.fetch(request);
}

Adding Response Headers Uniformly

After retrieving the project response, add response headers uniformly and return it.
async function onRequest(context) {
const response = await context.fetch(context.request);
const headers = new Headers(response.headers);
headers.set("x-middleware", "1");
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers,
});
}

ai-agent