feat: 后端代理层(Jev 透传 + ASR 预留端点),前端支持代理模式

This commit is contained in:
Jayway Liu
2026-10-03 12:55:00 +08:00
parent bed4d734ca
commit 6117ef894f
15 changed files with 740 additions and 11 deletions
+31
View File
@@ -0,0 +1,31 @@
/**
* Jev 代理路由:POST /api/jev
* 透传 systemone 请求到 https://api.typesafe.ai/v1/systemone,
* key 从服务端环境变量 TYPESAFE_API_KEY 读取(不下发到前端)。
* 上游状态码(401/422/429/529 等)与响应体原样透传回前端。
* key 永不写入日志或响应。
*/
import { Hono } from 'hono';
const UPSTREAM_URL = 'https://api.typesafe.ai/v1/systemone';
export const jevRoute = new Hono().post('/', async (c) => {
const apiKey = process.env.TYPESAFE_API_KEY;
if (!apiKey) {
return c.json({ error: 'server 未配置 TYPESAFE_API_KEY(见 server/README.md)' }, 503);
}
const body = await c.req.text(); // 请求体原样透传,不解析不修改
const upstream = await fetch(UPSTREAM_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body,
});
const text = await upstream.text();
return new Response(text, {
status: upstream.status,
headers: { 'Content-Type': upstream.headers.get('content-type') ?? 'application/json' },
});
});