This commit is contained in:
2026-04-22 23:44:57 +08:00
parent 76ac9d22a5
commit 84dc92646a
484 changed files with 9598 additions and 9135 deletions

View File

@@ -18,6 +18,7 @@ import { routeMeta } from '../middleware/routeMeta.js';
const BIG_FISH_ROUTE_VERSION = '2026-04-22';
const DEFAULT_RUST_API_TARGET = 'http://127.0.0.1:3100';
const DEFAULT_INTERNAL_API_SECRET = 'genarrative-dev-internal-bridge';
const BIG_FISH_UPSTREAM_TIMEOUT_MS = 15000;
const INTERNAL_USER_HEADER = 'x-genarrative-authenticated-user-id';
const INTERNAL_SECRET_HEADER = 'x-genarrative-internal-api-secret';
@@ -106,12 +107,17 @@ async function proxyBigFishRequest(params: {
: undefined;
let upstreamResponse: globalThis.Response;
const controller = new AbortController();
const timeoutId = setTimeout(() => {
controller.abort();
}, BIG_FISH_UPSTREAM_TIMEOUT_MS);
try {
upstreamResponse = await fetch(upstreamUrl, {
method,
// 这里显式转发“已通过 Node 校验的用户身份”,让 Big Fish 继续由 Rust 真相后端处理。
headers: pickForwardHeaders(request, context, userId),
body,
signal: controller.signal,
});
} catch (error) {
request.log?.error(
@@ -122,7 +128,13 @@ async function proxyBigFishRequest(params: {
},
'big fish upstream request failed',
);
throw upstreamError('大鱼吃小鱼后端暂时不可用');
throw upstreamError(
error instanceof Error && error.name === 'AbortError'
? '大鱼吃小鱼后端响应超时'
: '大鱼吃小鱼后端暂时不可用',
);
} finally {
clearTimeout(timeoutId);
}
prepareApiResponse(request, response, {

View File

@@ -18,6 +18,7 @@ import { routeMeta } from '../middleware/routeMeta.js';
const PUZZLE_ROUTE_VERSION = '2026-04-22';
const DEFAULT_RUST_API_TARGET = 'http://127.0.0.1:3100';
const DEFAULT_INTERNAL_API_SECRET = 'genarrative-dev-internal-bridge';
const PUZZLE_UPSTREAM_TIMEOUT_MS = 15000;
const INTERNAL_USER_HEADER = 'x-genarrative-authenticated-user-id';
const INTERNAL_SECRET_HEADER = 'x-genarrative-internal-api-secret';
@@ -106,11 +107,16 @@ async function proxyPuzzleRequest(params: {
: undefined;
let upstreamResponse: globalThis.Response;
const controller = new AbortController();
const timeoutId = setTimeout(() => {
controller.abort();
}, PUZZLE_UPSTREAM_TIMEOUT_MS);
try {
upstreamResponse = await fetch(upstreamUrl, {
method,
headers: pickForwardHeaders(request, context, userId),
body,
signal: controller.signal,
});
} catch (error) {
request.log?.error(
@@ -121,7 +127,13 @@ async function proxyPuzzleRequest(params: {
},
'puzzle upstream request failed',
);
throw upstreamError('拼图后端暂时不可用');
throw upstreamError(
error instanceof Error && error.name === 'AbortError'
? '拼图后端响应超时'
: '拼图后端暂时不可用',
);
} finally {
clearTimeout(timeoutId);
}
prepareApiResponse(request, response, {