Skip to content

Commit c30fa4c

Browse files
committed
fix: 404, 500 bug
1 parent 36786a1 commit c30fa4c

File tree

6 files changed

+38
-21
lines changed

6 files changed

+38
-21
lines changed

next-sitemap.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ module.exports = {
99
changefreq: 'daily',
1010
priority: 0.7,
1111
generateRobotsTxt: true,
12-
exclude: ['/tachi', '/help', '/search'],
12+
exclude: [
13+
'/tachi',
14+
'/user/login',
15+
'/help',
16+
'*/search*',
17+
'*/periodical/statistics/click*',
18+
],
1319

1420
robotsTxtOptions: {
1521
additionalSitemaps: [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build:dep": "cross-env ANALYZE=true next build",
99
"start": "next start",
1010
"server_start": "pm2 start ecosystem.config.js",
11-
"server_reload": "next-sitemap --config next-sitemap.config.js && next build && pm2 reload ecosystem.config.js",
11+
"server_reload": "next build && next-sitemap --config next-sitemap.config.js && pm2 reload ecosystem.config.js",
1212
"server_stop": "pm2 stop ecosystem.config.js",
1313
"lint": "next lint",
1414
"lint:fix": "eslint src --fix && yarn format",

server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ const handleRedirect = (req, res, locale, urlLocale) => {
3838
}
3939
if (locale === DEFAULT_LOCALE) {
4040
const newUrl = req.url.replace(`/${DEFAULT_LOCALE}`, '') || '/';
41-
return res.redirect(307, newUrl);
41+
res.redirect(307, newUrl);
42+
return true;
4243
}
4344
} else if (locale !== DEFAULT_LOCALE) {
4445
let newUrl = `/${locale}${req.url}`;
4546
if (newUrl.endsWith('/') && newUrl.length > 1) {
4647
newUrl = newUrl.slice(0, -1);
4748
}
48-
return res.redirect(307, newUrl);
49+
res.redirect(307, newUrl);
50+
return true;
4951
}
5052
return false;
5153
};

src/pages/index.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ import IndexBar from '@/components/navbar/IndexBar';
1414
import Seo from '@/components/Seo';
1515
import ToTop from '@/components/toTop/ToTop';
1616

17+
const validSortBy = ['featured', 'all'];
18+
1719
const Index: NextPage = () => {
1820
const { t, i18n } = useTranslation('home');
1921
const router = useRouter();
20-
const { sort_by = 'featured', tid = '' } = router.query;
22+
const { sort_by = 'featured', tid = '' }: { sort_by?: string; tid?: string } =
23+
router.query;
24+
const sortBy = validSortBy.includes(sort_by) ? sort_by : 'featured';
2125

2226
const { isLogin } = useLoginContext();
2327
const { repositories, isValidating, hasMore, size, sentryRef } =
24-
useRepositories(sort_by as string, tid as string);
28+
useRepositories(sortBy, tid);
2529

2630
const handleItemBottom = () => {
2731
if (!isValidating && !hasMore) {
@@ -37,12 +41,7 @@ const Index: NextPage = () => {
3741
return (
3842
<>
3943
<Seo title={t('title')} description={t('description')} />
40-
<IndexBar
41-
tid={tid as string}
42-
sort_by={sort_by as string}
43-
t={t}
44-
i18n_lang={i18n.language}
45-
/>
44+
<IndexBar tid={tid} sort_by={sortBy} t={t} i18n_lang={i18n.language} />
4645
<div className='h-screen'>
4746
<Items repositories={repositories} i18n_lang={i18n.language} />
4847
<div

src/pages/tags/[tid].tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,24 @@ export const getServerSideProps: GetServerSideProps = async ({
4242
const ip = getClientIP(req);
4343
const tid = query?.tid as string;
4444
const data = await getTagPageItems(ip, tid);
45-
const tag_name =
46-
locale == 'en' && data.tag_name_en ? data.tag_name_en : data.tag_name;
47-
return {
48-
props: {
49-
...(await serverSideTranslations(locale as string, ['common', 'topic'])),
50-
items: data.data,
51-
tag_name: tag_name,
52-
},
53-
};
45+
if (data.success) {
46+
const tag_name =
47+
locale == 'en' && data.tag_name_en ? data.tag_name_en : data.tag_name;
48+
return {
49+
props: {
50+
...(await serverSideTranslations(locale as string, [
51+
'common',
52+
'topic',
53+
])),
54+
items: data.data,
55+
tag_name: tag_name,
56+
},
57+
};
58+
} else {
59+
return {
60+
notFound: true,
61+
};
62+
}
5463
};
5564

5665
export default TagPage;

src/types/tag.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface TagPageProps {
88
}
99

1010
export interface TagPage {
11+
success: boolean;
1112
page: number;
1213
data: HomeItem[];
1314
tid: string;

0 commit comments

Comments
 (0)