forked from coinbase/coinbase-sdk-ai-agent-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
34 lines (29 loc) · 857 Bytes
/
middleware.ts
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
34
import { geolocation, next } from '@vercel/edge';
// List of blocked countries (ISO 3166-1 alpha-2 country codes)
// North Korea (KP), Iran (IR), Syria (SY), Cuba (CU), Crimea (UA-43), Luhansk (UA-09), Donetsk (UA-14)
const BLOCKED_COUNTRIES = [
'KP',
'IR',
'SY',
'CU',
'UA-43',
'UA-09',
'UA-14',
'UNKNOWN',
];
export const config = {
matcher: ['/'],
};
export default function middleware(request: Request) {
console.log('inside middleware')
const url = new URL(request.url);
const { country } = geolocation(request);
const countryCode = country || 'UNKNOWN';
if (
BLOCKED_COUNTRIES.includes(countryCode)
) {
console.log(`Country ${countryCode} is blocked`)
return new Response('AI agent app not available in your country', { status: 403 });
}
return next();
}