-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Middleware in my api folder.
import { NextResponse } from "next/server";
export async function middleware(req) {
const { nextUrl: url, geo } = req;
console.log(url);
console.log(geo);
if (url.pathname === "/api/ip-info") {
const country = geo.country || "";
const region = geo.region || "";
url.searchParams.set("countryCode", country);
url.searchParams.set("region", region);
return NextResponse.rewrite(url);
}
return NextResponse.next();
}
Logs from Vercel.
/api/ip-info
{ city: undefined,
country: undefined,
region: undefined,
latitude: undefined,
longitude: undefined }
What am I missing?
The request is triggered via the CookieConsent consentTypeRequired
function.
<>
<Head>
<meta
name="viewport"
content="minimum-scale=1, initial-scale=1, maximum-scale=5, width=device-width, shrink-to-fit=no, viewport-fit=cover"
/>
</Head>
<DefaultSeo {...SEO} />
<CookieConsentProvider consentTypeRequired={consentTypeRequired}>
<Component {...pageProps} />
<CookieConsent />
</CookieConsentProvider>
</>
Is there anything I could simplify? Currently I have a fallback in the ip-info api that uses external services to determine the geo. However that causes initial delays.
agungsb, arendondiosa and judewang
Metadata
Metadata
Assignees
Labels
No labels