-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
54 lines (43 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
51
52
53
54
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
//declare & store country
const us = "US",
bd = "BD",
gb = "GB",
ae = "AE";
export const config = {
matcher: "/",
};
export default function middleware(req: NextRequest) {
// const country = req.geo?.country || "GB";
const country = (req.geo && req.geo.country) || "GB";
// Specify the correct pathname
if (country === bd) {
req.nextUrl.pathname = "/bd";
} else if (country === us) {
req.nextUrl.pathname = `/us`;
} else if (country === ae) {
req.nextUrl.pathname = "/ae";
} else {
req.nextUrl.pathname = "/gb";
}
// Rewrite to URL
// return NextResponse.rewrite(req.nextUrl);
return NextResponse.redirect(req.nextUrl);
// const country = req.geo?.country;
// if (req.nextUrl.pathname === "/bd") {
// return NextResponse.next();
// }
// if (country === us) {
// return NextResponse.redirect("/us");
// }
// if (country === bd) {
// return NextResponse.redirect("/bd");
// }
// if (country === ae) {
// return NextResponse.redirect("/ae");
// }
// if (country === gb) {
// return NextResponse.redirect("/gb");
// }
}