diff --git a/.env.example b/.env.example index ead5522..6203304 100644 --- a/.env.example +++ b/.env.example @@ -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= diff --git a/config/development.env b/config/development.env index ab6834d..bee73b5 100644 --- a/config/development.env +++ b/config/development.env @@ -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 diff --git a/config/production.env b/config/production.env index 421089d..a05eed8 100644 --- a/config/production.env +++ b/config/production.env @@ -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 diff --git a/config/test.env b/config/test.env index 4925cbb..4ad7e22 100644 --- a/config/test.env +++ b/config/test.env @@ -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 diff --git a/next-env.d.ts b/next-env.d.ts index ce4e94a..6936789 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,7 +1,7 @@ /// /// -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. diff --git a/src/lib/api/config.ts b/src/lib/api/config.ts index 8153a4f..76da5e9 100644 --- a/src/lib/api/config.ts +++ b/src/lib/api/config.ts @@ -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 { diff --git a/src/lib/seo.ts b/src/lib/seo.ts index b6b183f..f6b168d 100644 --- a/src/lib/seo.ts +++ b/src/lib/seo.ts @@ -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}; diff --git a/tests/api-config.test.mjs b/tests/api-config.test.mjs index 533a063..7af073f 100644 --- a/tests/api-config.test.mjs +++ b/tests/api-config.test.mjs @@ -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"); diff --git a/tests/environment.test.mjs b/tests/environment.test.mjs index 44aa63a..7e0588a 100644 --- a/tests/environment.test.mjs +++ b/tests/environment.test.mjs @@ -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(