Skip to content

Commit

Permalink
update: server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
521xueweihan committed Aug 14, 2024
1 parent 9f1ff53 commit f6ea04c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ CHANGELOG.md

# yarn
.yarn

# data
/data
9 changes: 0 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/buttons/LanguageSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const LanguageSwitcher = (props: LanguageSwitchProps) => {
aria-expanded={isHovered ? 'true' : 'false'}
>
{/* <MdTranslate size={16} /> */}
{selectedLocale === 'zh' ? '中文' : 'EN'}
{selectedLocale === 'zh' ? 'EN' : '中文'}
</button>
</div>

Expand Down

0 comments on commit f6ea04c

Please sign in to comment.