-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.ts
More file actions
33 lines (28 loc) · 896 Bytes
/
middleware.ts
File metadata and controls
33 lines (28 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { type NextRequest, NextResponse } from 'next/server';
export const config = {
matcher: [
/*
* Match all paths except for:
* 1. /api routes
* 2. /_next (Next.js internals)
* 3. /_static (inside /public)
* 4. all root files inside /public (e.g. /favicon.ico)
*/
'/((?!api/|fonts/|images/|_next/|_static/|_vercel|[\\w-]+\\.\\w+).*)',
],
};
const excludedPaths = ['/signin', '/signup', '/biz'];
// This function can be marked `async` if using `await` inside
export function middleware(request: NextRequest) {
const hostname = request.headers.get('host');
const { pathname } = request.nextUrl;
if (
hostname?.startsWith('biz') &&
!excludedPaths.some((path) => pathname.startsWith(path))
) {
return NextResponse.rewrite(
new URL(`/biz${request.nextUrl.pathname}`, request.url),
);
}
return NextResponse.next();
}