快速开始
安装 CLI、登录并发布 Worker。
1. 安装 CLI
支持 macOS、Linux 与 WSL。安装脚本会先校验校验和再放入 PATH。
$ curl -fsSL https://gitflare.net/install.sh | bash $ gitflare version
2. 认证
在控制台创建带 Workers:Edit 与 Zone:Read 的令牌,每台机器登录一次。
$ export GITFLARE_API_TOKEN=gf_live_... $ gitflare login --token "$GITFLARE_API_TOKEN"
3. 最小 Worker
保存为 src/index.js。读取 KV,并给响应加上短缓存,方便东京 colo 本地回答重复 GET。
export default {
async fetch(request, env) {
const url = new URL(request.url);
const user = await env.USERS.get(url.searchParams.get("id") || "anon");
return new Response(JSON.stringify({ ok: true, user }), {
headers: {
"content-type": "application/json",
"cache-control": "public, max-age=30",
"x-gitflare-colo": request.cf.colo,
},
});
},
};
4. 绑定 KV 并部署
$ gitflare kv namespace create USERS $ gitflare deploy --name hello --edge nearest --kv USERS=USERS
第一次请求会调度到最近的健康节点,在日本通常是 NRT-1 或 HND-1。
5. 绑定主机名
$ gitflare hostname add hello.example.com --worker hello $ curl -sS https://hello.example.com/?id=42