From 548155625dd4ce5c6b2fe4b2cd070e06d3f9229a Mon Sep 17 00:00:00 2001 From: toom1996 <23cm.cn@gmail.com> Date: Mon, 14 Sep 2026 00:42:45 +0800 Subject: [PATCH] update --- astro.config.mjs | 17 +- src/components/AuthModal.astro | 3 +- src/components/Index.astro | 3 +- src/components/Item.astro | 5 +- src/components/RunwayLooks.astro | 3 +- src/components/StreetSnap.astro | 5 +- src/components/StreetSnaps.astro | 3 +- src/layouts/Layout.astro | 6 +- src/lib/api.ts | 505 ++++++++++++++++++------------- src/lib/auth.ts | 193 ++++-------- src/lib/config/env.dev.ts | 11 + src/lib/config/env.prod.ts | 14 + src/lib/config/index.ts | 46 +++ src/lib/config/types.ts | 15 + src/lib/favorites.ts | 61 ++-- src/lib/history.ts | 48 ++- src/lib/http.ts | 21 +- src/lib/request.ts | 192 ++++++++++++ src/pages/cn/account.astro | 2 +- src/pages/cn/login.astro | 3 +- src/pages/en/account.astro | 2 +- src/pages/en/login.astro | 3 +- 22 files changed, 707 insertions(+), 454 deletions(-) create mode 100644 src/lib/config/env.dev.ts create mode 100644 src/lib/config/env.prod.ts create mode 100644 src/lib/config/index.ts create mode 100644 src/lib/config/types.ts create mode 100644 src/lib/request.ts diff --git a/astro.config.mjs b/astro.config.mjs index 532540e..a131aee 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,5 +1,5 @@ // @ts-check -import { defineConfig, envField } from 'astro/config'; +import { defineConfig } from 'astro/config'; import { fileURLToPath } from 'node:url'; import tailwindcss from '@tailwindcss/vite'; @@ -41,17 +41,6 @@ export default defineConfig({ mode: 'standalone' }), - // 环境变量声明:统一命名规范 - // BASE_API —— 公开/运行期 API 基址(浏览器 + 按需渲染共用,空 = 同源 /api) - // BASE_API_SSG —— 构建期 SSG 内部端口基址(仅服务端,绝不进前端 bundle) - // SSG_TOKEN —— SSG 内部接口可选访问令牌(仅服务端) - // 注意:Astro 仅自动把 PUBLIC_ 前缀变量暴露给客户端,BASE_API 没有该前缀, - // 故必须在 schema 中声明为 access:'public',否则浏览器端 import.meta.env.BASE_API 为 undefined。 - env: { - schema: { - BASE_API: envField.string({ context: 'client', access: 'public', optional: true }), - BASE_API_SSG: envField.string({ context: 'server', access: 'secret', optional: true }), - SSG_TOKEN: envField.string({ context: 'server', access: 'secret', optional: true }), - }, - }, + // base 地址配置已迁到 src/lib/config(dev/prod 两份 TS,缺则抛异常)。 + // 仅「密钥」类仍走构建期 env(如 SSG_TOKEN),不在此声明,也不进客户端 bundle。 }); \ No newline at end of file diff --git a/src/components/AuthModal.astro b/src/components/AuthModal.astro index 0d01d51..3167653 100644 --- a/src/components/AuthModal.astro +++ b/src/components/AuthModal.astro @@ -66,7 +66,8 @@ const fullLoginLabel = t('go to full login')