-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use edge geolocation to center the map
- Loading branch information
Rupert Redington
committed
Sep 25, 2024
1 parent
b2d6c58
commit 40e4d71
Showing
2 changed files
with
32 additions
and
2 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,16 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
// run only on homepage | ||
export const config = { | ||
matcher: '/', | ||
}; | ||
|
||
export async function middleware(req: NextRequest) { | ||
const { nextUrl: url, geo } = req; | ||
console.log(geo); | ||
if (!url.searchParams.has('lat') && geo && geo.latitude && geo.longitude) { | ||
url.searchParams.append('lat', geo.latitude); | ||
url.searchParams.append('lng', geo.longitude); | ||
return NextResponse.redirect(url); | ||
} | ||
} |
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