fix(web): 生产环境忽略本机 API 地址

This commit is contained in:
Script Generator
2026-07-06 18:06:48 +08:00
parent a129edd9a4
commit 1b8c079c0d
2 changed files with 27 additions and 1 deletions

View File

@@ -12,6 +12,19 @@ test('API base defaults to same-origin in production and localhost in developmen
);
});
test('API base ignores local-only absolute URLs in production', () => {
for (const localApiUrl of [
'http://localhost:3001/api/v1',
'http://127.0.0.1:3001/api/v1',
'http://0.0.0.0:3001/api/v1',
]) {
assert.equal(
resolveApiBase({ NODE_ENV: 'production', NEXT_PUBLIC_API_URL: localApiUrl }),
'/api/v1',
);
}
});
test('API requests use the resolved base path', async () => {
const originalFetch = globalThis.fetch;
const apiBase = resolveApiBase();