Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for next15 geolocation #617

Merged
merged 2 commits into from
Nov 6, 2024
Merged

feat: add support for next15 geolocation #617

merged 2 commits into from
Nov 6, 2024

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Nov 6, 2024

No description provided.

Next15 moves the geolocation information from a geo property on the request to `x-vercel-ip` headers.
`@vercel/functions` has a `geolocation` helper function to access those.
Copy link

changeset-bot bot commented Nov 6, 2024

🦋 Changeset detected

Latest commit: f267083

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@opennextjs/aws Patch
app-pages-router Patch
app-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Nov 6, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@opennextjs/aws@617

commit: f267083

Copy link
Contributor

github-actions bot commented Nov 6, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 22.42% 1650 / 7357
🔵 Statements 22.42% 1650 / 7357
🔵 Functions 56.81% 100 / 176
🔵 Branches 70.67% 417 / 590
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/open-next/src/core/routingHandler.ts 0% 0% 0% 0% 1-242
packages/open-next/src/core/routing/matcher.ts 78.13% 67.39% 91.66% 78.13% 36-38, 47-51, 56-58, 61, 100, 102, 105, 108, 118-119, 161-163, 272-274, 276-289, 368-407
packages/open-next/src/core/routing/middleware.ts 96.89% 85.29% 50% 96.89% 34-37, 120
packages/open-next/src/overrides/converters/aws-cloudfront.ts 70.31% 80.76% 100% 70.31% 104-105, 155-214
packages/open-next/src/overrides/wrappers/cloudflare.ts 0% 100% 100% 0% 9-60
Generated in workflow #708 for commit f267083 by the Vitest Coverage Report Action

Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misunderstood what we were discussing on discord, i added a few comment to explain

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i misunderstood what you were saying on discord, we don't want to modify this but the cloudfront function in sst.
This one is only used when using lambda@edge (either with external middleware or as a full server fuction).
If we'd do that we'll also have to modify the other lambda converter

If we'd want to provide these headers for every function, we could keep the x-open-next one in the cloudfront functions and we apply the x-vercel in here :

export default async function routingHandler(

We could add a function there that would add the x-vercel headers only if the x-open-next headers are present

@@ -6,12 +6,20 @@ import type {

import type { MiddlewareOutputEvent } from "../../core/routingHandler";

const cfPropNameToHeaderName = {
city: "x-vercel-ip-city",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide to change the headers in routingHandler then it would make sense to rename those as x-open-next

@vicb vicb force-pushed the next15-geo branch 6 times, most recently from af4ceaf to 6e66659 Compare November 6, 2024 12:59
@vicb
Copy link
Contributor Author

vicb commented Nov 6, 2024

@conico974 PTAL - I think it's better... after 25 force pushes 🤣

Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little note, other than that LGTM !!

@@ -149,7 +143,7 @@ export function addNextConfigHeaders(
source,
locale,
} of configHeaders) {
const path = locale === false ? rawPath : localizedRawPath;
const path = locale === false ? event.rawPath : localizePath(event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The localizePath was done outside in order to avoid recomputing the same value for every value.
Not that big of a deal but worth mentioning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOps, I missed that, I'll revert

@vicb vicb merged commit 6f798de into main Nov 6, 2024
3 checks passed
@vicb vicb deleted the next15-geo branch November 6, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants