diff --git a/client/components/error/index.tsx b/client/components/error/index.tsx new file mode 100644 index 0000000..af4c2c3 --- /dev/null +++ b/client/components/error/index.tsx @@ -0,0 +1,19 @@ +import { Page } from '@geist-ui/core' + +const Error = ({ status }: { + status: number +}) => { + return ( + + {status === 404 ? ( +

This page cannot be found.

+ ) : ( +
+

An error occurred: {status}

+
+ )} +
+ ) +} + +export default Error diff --git a/client/pages/_error.tsx b/client/pages/_error.tsx new file mode 100644 index 0000000..6f11877 --- /dev/null +++ b/client/pages/_error.tsx @@ -0,0 +1,17 @@ +import ErrorComponent from '@components/error' + +function Error({ statusCode }: { + statusCode: number +}) { + return +} + +Error.getInitialProps = ({ res, err }: { + res: any + err: any +}) => { + const statusCode = res ? res.statusCode : err ? err.statusCode : 404 + return { statusCode } +} + +export default Error diff --git a/client/pages/_middleware.tsx b/client/pages/_middleware.tsx index a3bba44..bf2c2ee 100644 --- a/client/pages/_middleware.tsx +++ b/client/pages/_middleware.tsx @@ -1,14 +1,14 @@ import { NextFetchEvent, NextRequest, NextResponse } from 'next/server' -const PUBLIC_FILE = /.(.*)$/ +const PUBLIC_FILE = /\.(.*)$/ export function middleware(req: NextRequest, event: NextFetchEvent) { const pathname = req.nextUrl.pathname const signedIn = req.cookies['drift-token'] const getURL = (pageName: string) => new URL(`/${pageName}`, req.url).href const isPageRequest = - !PUBLIC_FILE.test(req.nextUrl.pathname) && - !req.nextUrl.pathname.startsWith('/api') && + !PUBLIC_FILE.test(pathname) && + !pathname.startsWith('/api') && // header added when next/link pre-fetches a route !req.headers.get('x-middleware-preflight')