-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initial pass at geoblocking * initial blocked page * fix: build * feat: region support * fix: add matcher to skip redirects to /blocked * chore: better matcher * chore: update copy
- Loading branch information
1 parent
a6d6ed6
commit f0a87e1
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
export const config = { | ||
matcher: ['/((?!blocked/_next/static/backgrounds/fonts/favicon).*)'], | ||
}; | ||
|
||
const BLOCKED_COUNTRIES = [ | ||
'CU', // Cuba | ||
'KP', // North Korea | ||
'RU', // Russia | ||
'AF', // Afghanistan | ||
'BY', // Belarus | ||
'BA', // Bosnia & Herzegovina | ||
'CF', // Central African Republic | ||
'CD', // Democratic Republic of the Congo | ||
'GN', // Guinea | ||
'GW', // Guinea-Bissau | ||
'HT', // Haiti | ||
'IQ', // Iraq | ||
'LB', // Lebanon | ||
'LY', // Libya | ||
'ML', // Mali | ||
'NI', // Nicaragua | ||
'SO', // Somalia | ||
'SS', // South Sudan | ||
'SD', // Sudan | ||
'VE', // Venezuela | ||
'YE', // Yemen | ||
'ZW', // Zimbabwe | ||
'MM', // Myanmar | ||
'SY', // Syria | ||
]; | ||
|
||
const BLOCKED_REGIONS = [ | ||
{ | ||
country: 'UA', // Ukraine | ||
regions: [ | ||
'43', // Crimea | ||
'14', // Donetsk | ||
'09', // Luhansk | ||
], | ||
}, | ||
]; | ||
|
||
export function middleware(req: NextRequest) { | ||
const country = req.geo?.country; | ||
const region = req.geo?.region; | ||
|
||
if (country && BLOCKED_COUNTRIES.includes(country)) { | ||
return NextResponse.redirect('/blocked'); | ||
} | ||
|
||
if ( | ||
country && | ||
region && | ||
BLOCKED_REGIONS.find((x) => x.country === country)?.regions.includes(region) | ||
) { | ||
return NextResponse.redirect('/blocked'); | ||
} | ||
|
||
return NextResponse.next(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ErrorBoundary } from '../components/errors/ErrorBoundary'; | ||
|
||
export default function Page() { | ||
return ( | ||
<ErrorBoundary> | ||
{(() => { | ||
throw new Error('Your region has been blocked from accessing this service'); | ||
})()} | ||
</ErrorBoundary> | ||
); | ||
} |