From f6ea04c81521727cd25834d1857c208fe5703571 Mon Sep 17 00:00:00 2001 From: xueweihan <595666367@qq.com> Date: Wed, 14 Aug 2024 15:41:24 +0800 Subject: [PATCH] update: server.js --- .prettierignore | 3 +++ server.js | 9 --------- src/components/buttons/LanguageSwitcher.tsx | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.prettierignore b/.prettierignore index 3380fd58..cad1e46c 100644 --- a/.prettierignore +++ b/.prettierignore @@ -39,3 +39,6 @@ CHANGELOG.md # yarn .yarn + +# data +/data diff --git a/server.js b/server.js index 1e51b817..eccd7cf6 100644 --- a/server.js +++ b/server.js @@ -51,11 +51,6 @@ const handleRedirect = (req, res, locale, urlLocale) => { return false; }; -const canSetCookie = (req) => { - // 检查请求头中是否有 'cookie' 字段 - return req.headers.cookie !== undefined; -}; - async function startServer() { try { await app.prepare(); @@ -75,10 +70,6 @@ async function startServer() { return; // 如果发生重定向,立即返回 } - // 检查响应头是否已经发送 - if (canSetCookie(req) && !res.headersSent) { - res.cookie('locale', locale, { maxAge: 365 * 24 * 60 * 60 * 1000 }); - } req.locale = locale; next(); }); diff --git a/src/components/buttons/LanguageSwitcher.tsx b/src/components/buttons/LanguageSwitcher.tsx index 06a8ca23..a214f326 100644 --- a/src/components/buttons/LanguageSwitcher.tsx +++ b/src/components/buttons/LanguageSwitcher.tsx @@ -62,7 +62,7 @@ const LanguageSwitcher = (props: LanguageSwitchProps) => { aria-expanded={isHovered ? 'true' : 'false'} > {/* */} - {selectedLocale === 'zh' ? '中文' : 'EN'} + {selectedLocale === 'zh' ? 'EN' : '中文'}