From 9cc0cdd38f6c547981124d600a6917d1086f9000 Mon Sep 17 00:00:00 2001 From: Agustinus Nathaniel Date: Wed, 29 Nov 2023 09:17:30 +0700 Subject: [PATCH] refactor: simplify middleware --- src/lib/constants/paths.ts | 1 - src/middleware.ts | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 src/lib/constants/paths.ts diff --git a/src/lib/constants/paths.ts b/src/lib/constants/paths.ts deleted file mode 100644 index 02dc7844..00000000 --- a/src/lib/constants/paths.ts +++ /dev/null @@ -1 +0,0 @@ -export const funPaths = ['why-i']; diff --git a/src/middleware.ts b/src/middleware.ts index 44007f6d..534c3d1e 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -4,10 +4,11 @@ import type { NextRequest } from 'next/server'; import { NextResponse } from 'next/server'; import { env } from '~/lib/constants/env'; -import { funPaths } from '~/lib/constants/paths'; + +const funPath = 'why-i'; export const middleware = async (req: NextRequest) => { - const isFunPath = !!funPaths.find((item) => req.nextUrl.href.includes(item)); + const isFunPath = !!req.nextUrl.href.includes(funPath); if (isFunPath) { return NextResponse.redirect(env.MM_URL); @@ -29,7 +30,7 @@ export const middleware = async (req: NextRequest) => { export const config = { matcher: [ '/((?!api|_next/static|_next/image|favicon.ico|manifest.json|robots.txt).*)', - ...funPaths.map((item) => `/${item}:path*`), + `/why-i:path*`, '/s/:path*', ], };