mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
added 500 page
This commit is contained in:
parent
07b4874f69
commit
83065e6bfd
2 changed files with 35 additions and 18 deletions
7
src/pages/500.tsx
Normal file
7
src/pages/500.tsx
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { NotFoundLayout } from '~/layouts/NotFoundLayout';
|
||||||
|
|
||||||
|
const InternalServerErrorPage = () => {
|
||||||
|
return <NotFoundLayout />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InternalServerErrorPage;
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
|
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { InferGetStaticPropsType } from 'next';
|
import { GetStaticPropsResult, InferGetStaticPropsType } from 'next';
|
||||||
import { RouteComponentProps } from 'react-router';
|
import { RouteComponentProps } from 'react-router';
|
||||||
|
|
||||||
import { apiGetNode, getNodeDiff } from '~/api/node';
|
import { apiGetNode, getNodeDiff } from '~/api/node';
|
||||||
|
@ -14,6 +14,7 @@ import { useNodePageParams } from '~/hooks/node/useNodePageParams';
|
||||||
import { useNodePermissions } from '~/hooks/node/useNodePermissions';
|
import { useNodePermissions } from '~/hooks/node/useNodePermissions';
|
||||||
import { useNodeTags } from '~/hooks/node/useNodeTags';
|
import { useNodeTags } from '~/hooks/node/useNodeTags';
|
||||||
import { NodeLayout } from '~/layouts/NodeLayout';
|
import { NodeLayout } from '~/layouts/NodeLayout';
|
||||||
|
import { ApiGetNodeResponse } from '~/types/node';
|
||||||
import { CommentContextProvider } from '~/utils/context/CommentContextProvider';
|
import { CommentContextProvider } from '~/utils/context/CommentContextProvider';
|
||||||
import { NodeContextProvider } from '~/utils/context/NodeContextProvider';
|
import { NodeContextProvider } from '~/utils/context/NodeContextProvider';
|
||||||
import { TagsContextProvider } from '~/utils/context/TagsContextProvider';
|
import { TagsContextProvider } from '~/utils/context/TagsContextProvider';
|
||||||
|
@ -42,28 +43,37 @@ export const getStaticPaths = async () => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getStaticProps = async context => {
|
export const getStaticProps = async (
|
||||||
if (!context.params?.id) {
|
context
|
||||||
return { props: {} };
|
): Promise<GetStaticPropsResult<{ fallbackData: ApiGetNodeResponse }>> => {
|
||||||
}
|
try {
|
||||||
|
if (!context.params?.id) {
|
||||||
|
return { notFound: true };
|
||||||
|
}
|
||||||
|
|
||||||
const id = parseInt(context.params.id, 10);
|
const id = parseInt(context.params.id, 10);
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return { props: {} };
|
return { notFound: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
const fallbackData = await apiGetNode({ id });
|
const fallbackData = await apiGetNode({ id });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
fallbackData: {
|
fallbackData: {
|
||||||
...fallbackData,
|
...fallbackData,
|
||||||
last_seen: fallbackData.last_seen ?? null,
|
last_seen: fallbackData.last_seen ?? null,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
revalidate: 7 * 86400, // every week
|
||||||
revalidate: 7 * 86400, // every week
|
};
|
||||||
};
|
} catch (error) {
|
||||||
|
console.warn(`[NEXT] can't generate node: `, error);
|
||||||
|
return {
|
||||||
|
notFound: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = RouteComponentProps<{ id: string }> & InferGetStaticPropsType<typeof getStaticProps>;
|
type Props = RouteComponentProps<{ id: string }> & InferGetStaticPropsType<typeof getStaticProps>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue