From 1adf71248fec5fbaea4617937be3c2da21bbb9fa Mon Sep 17 00:00:00 2001
From: toom1996 <23cm.cn@gmail.com>
Date: Thu, 22 Oct 2026 10:36:49 +0800
Subject: [PATCH] update
---
package.json | 1 +
scripts/local-proxy.mjs | 57 ++++++++
src/components/ComingSoon.astro | 22 +--
src/components/views/Login.astro | 237 ++++++++++++++++++++++---------
src/layouts/Layout.astro | 93 ++++++------
src/lib/i18n/dictionary.ts | 33 ++++-
6 files changed, 319 insertions(+), 124 deletions(-)
create mode 100644 scripts/local-proxy.mjs
diff --git a/package.json b/package.json
index aae594c..8748e43 100644
--- a/package.json
+++ b/package.json
@@ -10,6 +10,7 @@
"dev": "astro dev",
"build": "astro build",
"preview": "astro preview",
+ "preview:full": "node scripts/local-proxy.mjs",
"check": "astro check",
"astro": "astro"
},
diff --git a/scripts/local-proxy.mjs b/scripts/local-proxy.mjs
new file mode 100644
index 0000000..5c85d37
--- /dev/null
+++ b/scripts/local-proxy.mjs
@@ -0,0 +1,57 @@
+// 本地预览用的极简代理:模拟生产里 proxy(nginx) 的分流。
+//
+// /api/* → 后端(默认 127.0.0.1:8090)
+// 其余 → astro preview(默认 127.0.0.1:4322)
+//
+// 为什么需要它:生产环境里浏览器只访问一个域名,/api 由 nginx 反代到后端;
+// 本地没有 nginx,astro preview 只跑 Astro 自己的路由,/api 会 404。
+// 这个脚本让本地的访问方式和生产一致(同源),不产生 CORS,也不需要改任何业务配置。
+//
+// 用法:
+// node scripts/local-proxy.mjs # 默认 http://localhost:8099
+// PROXY_PORT=9000 node scripts/local-proxy.mjs
+// (先启动 astro preview,再启动它)
+import http from 'node:http'
+
+const PORT = Number(process.env.PROXY_PORT || 8099)
+const WEB_ORIGIN = process.env.WEB_ORIGIN || 'http://127.0.0.1:4322'
+const API_ORIGIN = process.env.API_ORIGIN || 'http://127.0.0.1:8090'
+
+const server = http.createServer((req, res) => {
+ const url = req.url || '/'
+ const isApi = url === '/api' || url.startsWith('/api/')
+ const target = new URL(url, isApi ? API_ORIGIN : WEB_ORIGIN)
+
+ const proxyReq = http.request(
+ {
+ protocol: target.protocol,
+ hostname: target.hostname,
+ port: target.port,
+ path: target.pathname + target.search,
+ method: req.method,
+ headers: { ...req.headers, host: target.host },
+ },
+ (proxyRes) => {
+ res.writeHead(proxyRes.statusCode || 502, proxyRes.headers)
+ proxyRes.pipe(res)
+ }
+ )
+
+ proxyReq.on('error', (err) => {
+ // 后端没起 / preview 没起时给出明确提示,而不是挂住
+ res.writeHead(502, { 'content-type': 'text/plain; charset=utf-8' })
+ res.end(
+ `local-proxy: 连不上 ${isApi ? API_ORIGIN : WEB_ORIGIN}\n` +
+ `${err.message}\n\n` +
+ (isApi ? '先把后端跑起来(8090)\n' : '先跑 npm run preview(4322)\n')
+ )
+ })
+
+ req.pipe(proxyReq)
+})
+
+server.listen(PORT, () => {
+ console.log(`[local-proxy] http://localhost:${PORT}`)
+ console.log(` /api/* → ${API_ORIGIN}`)
+ console.log(` 其余 → ${WEB_ORIGIN}`)
+})
diff --git a/src/components/ComingSoon.astro b/src/components/ComingSoon.astro
index 3f055ad..660bd70 100644
--- a/src/components/ComingSoon.astro
+++ b/src/components/ComingSoon.astro
@@ -7,23 +7,27 @@ interface Props {
moduleZh?: string
note?: string
}
-const { module = "This module", moduleZh = "", note = "" } = Astro.props
-const { locale } = getI18n(Astro)
+const { module = "", moduleZh = "", note = "" } = Astro.props
+const { locale, t } = getI18n(Astro)
+
+// 原实现整段是硬编码中文,英文站会直接显示中文。这里全部走词典,
+// 模块名按语言取:中文优先 moduleZh,英文只取 module。
+const moduleLabel = locale === 'cn' ? moduleZh || module : module || moduleZh
---
{module}{moduleZh && ` · ${moduleZh}`} {moduleLabel}
- {note || "该模块正在筹备中,尚未对外开放。站点正按模块逐个完善,你可以先浏览已上线的走秀档案。"}
+ {note || t('This module is under construction and not open to the public yet. Browse the runway archive first.')}
暂未上线
- {t('Coming Soon')}
+