Skip to content

Commit 33c57e8

Browse files
authored
Disable contry redirects (#72)
* Disable contry redirects * Update middleware.ts
1 parent 43ff763 commit 33c57e8

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

middleware.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
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) => {}

0 commit comments

Comments
 (0)