-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmiddleware.ts
More file actions
29 lines (24 loc) · 860 Bytes
/
middleware.ts
File metadata and controls
29 lines (24 loc) · 860 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
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { SUPPORTED_CHAINS } from './constant/config/core.constant';
import { LOCAL_ROUTE } from './constant/routes/routes.constant';
export function middleware(request: NextRequest) {
// Only redirect if the path is exactly the root
if (request.nextUrl.pathname === '/') {
// Get the first supported chain from the array
const [firstChain] = SUPPORTED_CHAINS;
// Create the new URL with the first chain as the path
const url = new URL(
`/${firstChain}` + LOCAL_ROUTE.EARN.HOME,
request.url
);
// Return a redirect response
return NextResponse.redirect(url);
}
// For all other paths, continue with the request
return NextResponse.next();
}
// Configure the middleware to only run on the homepage
export const config = {
matcher: '/',
};