🔧 API 部署配置 (Scheme B)
安全提示: 建议您使用推荐的“安全代理模式”。如果您当前仅用于本地快速测试,可选择“前端直连模式”并直接在下方粘贴您的 Gemini Key。该 Key 将加密存储于您的本地浏览器中,绝不上传,避免源码泄露。
Cloudflare Workers 部署代码 (最推荐、免服务器、国内无限制):
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
// 处理跨域 (CORS) 预检请求
if (request.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
}
});
}
if (request.method !== "POST") {
return new Response("Method Not Allowed", { status: 405 });
}
try {
const GEMINI_API_KEY = "您申请的GEMINI_API_KEY"; // 替换您的 Key
const payload = await request.json();
// 转发请求给官方接口 (在国外CF节点自动连通)
const targetUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-09-2025:generateContent?key=${GEMINI_API_KEY}`;
const response = await fetch(targetUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
const data = await response.json();
return new Response(JSON.stringify(data), {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
}
});
} catch (err) {
return new Response(JSON.stringify({ error: err.message }), { status: 500 });
}
}
输入您的背景(如年龄、资产、行业等),AI 将基于腾町香港与全球化合规数据库为您生成初步路径建议。