Skip to content

Commit

Permalink
refactor: middleware を通過しなくて良いパスを配列で列挙する
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Jun 28, 2024
1 parent 51c6f64 commit e040e76
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ export const middleware = async (request: NextRequest) => {
if (request.method !== 'GET') {
return;
}

const pathName = request.nextUrl.pathname.toLowerCase();
const ignorePaths = [
'/_next',
'/login',
'/logout',
'/internal-error',
'/forbidden',
'/unknown-error',
'/badrequest',
'/api',
];

if (
pathName === '/' ||
pathName.startsWith('/login') ||
pathName.startsWith('/logout') ||
pathName.startsWith('/_next') ||
pathName.startsWith('/internal-error') ||
pathName.startsWith('/forbidden') ||
pathName.startsWith('/unknown-error') ||
pathName.startsWith('/badrequest') ||
pathName.startsWith('/api')
ignorePaths.some((path) => pathName.startsWith(path))
) {
return;
}
Expand Down

0 comments on commit e040e76

Please sign in to comment.