File tree Expand file tree Collapse file tree 1 file changed +2
-26
lines changed
Expand file tree Collapse file tree 1 file changed +2
-26
lines changed Original file line number Diff line number Diff line change 1- import { NextMiddleware , NextResponse } from 'next/server'
2- import { isMainlandChinaCluster } from 'utils/config'
1+ import { NextMiddleware } from 'next/server'
32
4- const countryRedirects : Partial < Record < string , string > > = {
5- CN : 'https://linearmouse.cn'
6- }
7-
8- export const middleware : NextMiddleware = ( req ) => {
9- if ( isMainlandChinaCluster ) return
10-
11- // no contry redirect?
12- if ( req . cookies . get ( 'NCR' ) ?. value === '1' ) return
13-
14- // set no-contry-redirect cookie?
15- if ( req . nextUrl . pathname === '/ncr/' ) {
16- const res = NextResponse . redirect ( new URL ( '/' , req . url ) , { status : 307 } )
17- res . cookies . set ( 'NCR' , '1' , { path : '/' , maxAge : 31536000 } )
18- return res
19- }
20-
21- // country redirect
22- const ipCountry = req . headers . get ( 'Cf-Ipcountry' )
23- if ( ! ipCountry || ! Object . hasOwn ( countryRedirects , ipCountry ) ) return
24- const redirectTo = countryRedirects [ ipCountry ]
25- if ( ! redirectTo ) return
26- return NextResponse . redirect ( redirectTo , { status : 307 } )
27- }
3+ export const middleware : NextMiddleware = ( req ) => { }
You can’t perform that action at this time.
0 commit comments