api替换

This commit is contained in:
谢宇宁
2026-11-07 11:18:11 +07:00
parent 37411fcada
commit 58f097fe27
9 changed files with 22 additions and 17 deletions
+3 -2
View File
@@ -1,7 +1,8 @@
# Legacy development-only .env.local example. Prefer config/development.local.env.
# Development uses this configured backend; browsers call the current site's /api/app/*.
# Test uses this same backend; production uses http://172.104.56.28:26125.
UPSTREAM_API_URL=http://172.104.181.99:26792
UPSTREAM_API_URL=https://webhgcapi.mfcg.me
# Canonical site origin for SEO; overrides config/info foreverUrlAddr.
NEXT_PUBLIC_SITE_URL=https://huangguoai.info
# API_BASE_URL remains supported for existing local overrides.
# Optional channel code passed when creating a guest account.
API_CHANNEL=
+3 -1
View File
@@ -2,6 +2,8 @@
APP_ENV=development
PORT=21030
# Server-only Go API origin. Browser requests use the current site's /api/app/*.
UPSTREAM_API_URL=http://172.104.181.99:26792
UPSTREAM_API_URL=https://webhgcapi.mfcg.me
# Canonical site origin for SEO (canonical, sitemap, robots, JSON-LD).
NEXT_PUBLIC_SITE_URL=https://huangguoai.info
API_CHANNEL=
PUBLIC_DATA_CACHE_TTL_MS=0
+3 -1
View File
@@ -4,6 +4,8 @@ APP_ENV=production
# 应用接口在 21040。不要写成 H5 的 21042,也不要写 127.0.0.1(H5 进程里不一定能连到本机 Go)。
PORT=21042
# Server-only Go API origin. Browser requests use the current site's /api/app/*.
UPSTREAM_API_URL=http://139.162.49.252:21040
UPSTREAM_API_URL=https://webhgcapi.mfcg.me
# Canonical site origin for SEO (canonical, sitemap, robots, JSON-LD).
NEXT_PUBLIC_SITE_URL=https://huangguoai.info
API_CHANNEL=
PUBLIC_DATA_CACHE_TTL_MS=60000
+3 -1
View File
@@ -2,6 +2,8 @@
APP_ENV=test
PORT=21030
# Server-only Go API origin. Browser requests use the current site's /api/app/*.
UPSTREAM_API_URL=http://172.104.181.99:26792
UPSTREAM_API_URL=https://webhgcapi.mfcg.me
# Canonical site origin for SEO (canonical, sitemap, robots, JSON-LD).
NEXT_PUBLIC_SITE_URL=https://huangguoai.info
API_CHANNEL=
PUBLIC_DATA_CACHE_TTL_MS=60000
+2 -2
View File
@@ -1,7 +1,7 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
import "./.next/types/routes.d.ts";
import "./.next/types/root-params.d.ts";
import "./.next-dev/dev/types/routes.d.ts";
import "./.next-dev/dev/types/root-params.d.ts";
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
+2 -4
View File
@@ -1,4 +1,4 @@
export const DEFAULT_API_BASE_URL = 'http://172.104.181.99:26792';
export const DEFAULT_API_BASE_URL = 'https://webhgcapi.mfcg.me';
export const UPSTREAM_HOP_HEADER = 'x-jgdj-upstream';
export interface ApiRequestContext {
@@ -7,9 +7,7 @@ export interface ApiRequestContext {
}
function configuredApiUrl(): string {
const environment = process.env.APP_ENV || (process.env.NODE_ENV === 'production' ? 'production' : 'development');
const fallback = environment === 'production' ? 'http://139.162.49.252:21040' : DEFAULT_API_BASE_URL;
return (process.env.UPSTREAM_API_URL ?? process.env.API_BASE_URL ?? fallback).trim();
return (process.env.UPSTREAM_API_URL ?? process.env.API_BASE_URL ?? DEFAULT_API_BASE_URL).trim();
}
export function usesCurrentApiOrigin(): boolean {
+1 -1
View File
@@ -53,7 +53,7 @@ export function siteOrigin(value:unknown):string {
}catch{return '';}
}
export function seoEnvironment(config:Config={},categories:NavigationCategory[]=[]):SeoEnvironment {
const origin=siteOrigin(config.config?.foreverUrlAddr)||siteOrigin(config.newAddressInfo?.foreverUrlAddr);
const origin=siteOrigin(process.env.NEXT_PUBLIC_SITE_URL)||siteOrigin(config.config?.foreverUrlAddr)||siteOrigin(config.newAddressInfo?.foreverUrlAddr);
const channels={...config.newAddressInfo,...config.config};
const sameAs=[...new Set([channels.twitterAddr,channels.tgGroup].map(value=>schemaUrl(value,origin)).filter(Boolean))];
return {origin,site:normalizeSeo(config.seoInfo),navigation:normalizeSeo(config.seoNavInfo),categories:Array.isArray(categories)?categories.filter(item=>item&&typeof item==='object'):[],sameAs};
+3 -3
View File
@@ -56,11 +56,11 @@ sharedDependencies["../site-navigation"] = await compile("../site-navigation", {
test("development uses its configured domain and supports legacy overrides", () => {
delete environment.UPSTREAM_API_URL;
delete environment.API_BASE_URL;
assert.equal(config.getApiBaseUrl(), "http://172.104.181.99:26792");
assert.equal(config.getApiBaseUrl(), "https://webhgcapi.mfcg.me");
environment.APP_ENV = "test";
assert.equal(config.getApiBaseUrl(), "http://172.104.181.99:26792");
assert.equal(config.getApiBaseUrl(), "https://webhgcapi.mfcg.me");
environment.APP_ENV = "production";
assert.equal(config.getApiBaseUrl(), "http://139.162.49.252:21040");
assert.equal(config.getApiBaseUrl(), "https://webhgcapi.mfcg.me");
delete environment.APP_ENV;
environment.API_BASE_URL = "https://legacy-api.example/";
assert.equal(config.getApiBaseUrl(), "https://legacy-api.example");
+2 -2
View File
@@ -277,8 +277,8 @@ test("project profiles and Next configuration keep the requested API and port wi
assert.equal(
command.env.UPSTREAM_API_URL,
environment === "production"
? "http://139.162.49.252:21040"
: "http://172.104.181.99:26792",
? "https://webhgcapi.mfcg.me"
: "https://webhgcapi.mfcg.me",
);
assert.equal(command.env.API_BASE_URL, command.env.UPSTREAM_API_URL);
assert.equal(