-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmiddleware.ts
50 lines (37 loc) · 1.2 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import createMiddleware from "next-intl/middleware";
import { NextRequest, NextResponse } from "next/server";
import { locales, defaultLocale, localePrefix } from "./navigation";
const blockedGEOs: string[] = [""];
async function getGeo(ip: string): Promise<string> {
try {
const res = await fetch(`https://api.iplocation.net/?ip=${ip}`).then(
(res) => res.json(),
);
return res.country_code2;
} catch (err) {
console.log(err);
}
return "-";
}
export default async function middleware(request: NextRequest) {
const handleI18nRouting = createMiddleware({
locales,
defaultLocale,
localePrefix,
});
const response = handleI18nRouting(request);
// const ip = request.headers.get("X-Forwarded-For");
// const geo = ip ? await getGeo(ip) : "-";
console.log(new URL(request.url).pathname);
// if (
// blockedGEOs.includes(geo.toLowerCase()) &&
// new URL(request.url).pathname !== "/en/geo-blocked" &&
// new URL(request.url).pathname.includes("tizz-trade")
// ) {
// return NextResponse.redirect(new URL("/en/geo-blocked", request.url));
// }
return response;
}
export const config = {
matcher: ["/", "/(en|es|fr|hi|ja|pt|zh-CN)/:path*"],
};