この例では、VPC Network バインディングと Cloudflare Mesh(旧 WARP Connector)を使い、アカウント内の任意のプライベートサービスへ Worker から接続します。個別ホストの事前登録や Cloudflare Tunnel UUID の指定は不要です。
network_id: "cf1:network" で Cloudflare Mesh にバインドすると、Worker は任意の Mesh ノード、クライアントデバイス、Cloudflare Tunnel または Cloudflare Mesh 経由で広報されたサブネットまたはホスト名ルート、あるいは Cloudflare WAN オンランプ(GRE、IPsec、CNI)経由で接続された宛先に到達できます。
- プライベートネットワークに接続した Cloudflare Mesh ノード
- Mesh ノード背後で動くプライベートサービス(内部 API、データベース、Web アプリケーションなど)
Wrangler 設定で network_id: "cf1:network" を使い、Worker を Cloudflare Mesh にバインドします。
{
"$schema": "./node_modules/wrangler/config-schema.json",
"name": "mesh-gateway",
"main": "src/index.js",
// Set this to today's date
"compatibility_date": "2026-09-20",
"vpc_networks": [
{
"binding": "MESH",
"network_id": "cf1:network",
"remote": true
}
]
}"$schema" = "./node_modules/wrangler/config-schema.json"
name = "mesh-gateway"
main = "src/index.js"
# Set this to today's date
compatibility_date = "2026-09-20"
[[vpc_networks]]
binding = "MESH"
network_id = "cf1:network"
remote = trueこの 1 つのバインディングで、Worker はアカウント内のすべての Cloudflare Tunnel、Mesh ノード、Cloudflare WAN オンランプ上の任意のサービスに到達できます。
VPC Network バインディングを使い、プライベート IP アドレスでサービスにアクセスします。Cloudflare Mesh は現在、IP ベースのルーティングのみに対応しています。
// You can target a Mesh node directly by its Mesh IP or any private IP
// on a subnet route behind the node
const SERVICE_IP = "10.0.1.50";
const SERVICE_PORT = 8080;
export default {
async fetch(request, env, ctx) {
try {
const response = await env.MESH.fetch(
`http://${SERVICE_IP}:${SERVICE_PORT}/api/data`,
);
return response;
} catch (error) {
// fetch() throws if the VPC Network cannot connect to the target
return new Response("Service unavailable", { status: 503 });
}
},
};VPC Services とは異なり、fetch() に渡す URL または connect() に渡すアドレスが実際の宛先を決めます。サービスごとに別のバインディングを作らずに、Mesh ネットワーク経由で到達できる任意の IP とポートにアクセスできます。
同じバインディングの connect() で、非 HTTP サービスへの生の TCP ソケットも開けます。
// You can target a Mesh node directly by its Mesh IP or any private IP
// on a subnet route behind the node
const REDIS_IP = "10.0.1.50";
const REDIS_PORT = 6379;
export default {
async fetch(request, env, ctx) {
try {
const socket = await env.MESH.connect(`${REDIS_IP}:${REDIS_PORT}`);
const writer = socket.writable.getWriter();
await writer.write(new TextEncoder().encode("PING\r\n"));
await writer.close();
return new Response(socket.readable);
} catch (error) {
// connect() throws if the VPC Network cannot connect to the target
return new Response("Service unavailable", { status: 503 });
}
},
};Worker をデプロイし、プライベートサービスへ到達できることを確認します。
npx wrangler deploy# Test accessing the internal user API
curl https://mesh-gateway.workers.dev/api/users
# Test accessing metrics by private IP
curl https://mesh-gateway.workers.dev/api/metrics- VPC Networks の設定オプションを確認します
- Workers Binding API リファレンスを参照します
- アカウント向けに Cloudflare Mesh をセットアップ します
- ほかの例 を確認します