Giter Club home page Giter Club logo

Comments (9)

khuezy avatar khuezy commented on July 28, 2024 1

@fwang This can be closed; the geo data is available now.

from open-next.

fwang avatar fwang commented on July 28, 2024 1

Added in v1.2.0

from open-next.

conico974 avatar conico974 commented on July 28, 2024 1

@Makisuo request.geo does not work with OpenNext V3 at the moment. I'll add it back in the next releases, but it will require an update in the ion construct as well.
Right now you can use the cloudfront headers https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location

from open-next.

khuezy avatar khuezy commented on July 28, 2024

I tried changing the policy to origin request (redirects are changing the host to the middleware lambda domain, we'll need to update the x-forwarded-host to the original host so the user stays on the same domain). I'm still getting undefined geo data after the change...

I'm setting the header Cache-Control: public,s-maxage=0 so it behaves like "viewer request"

from open-next.

khuezy avatar khuezy commented on July 28, 2024

In the NextjsSite, can you add the CloudFront-Viewer-Country, etc... to the createCloudFrontServerCachePolicy function for middleware-function?

And in createCloudFrontDistributionForRegional, can you add this to the serverBehavior origin:

customHeaders: { 'x-origin-url': appDomain || fnUrl.url }

The Lambda Edge needs to read from the customHeaders field and set the host to that value and set the x-forwarded-host to itself.

ref:
https://github.com/jetbridge/cdk-nextjs/blob/main/assets/lambda%40edge/LambdaOriginRequest.ts#L32
https://github.com/jetbridge/cdk-nextjs/blob/main/src/NextjsDistribution.ts#L312

As for the middleware.ts redirects, I'm getting redirected to the raw lambda URL instead of my domain. The headers.location is not correctly set. I'm not sure if solving for the above will address the issue.

from open-next.

khuezy avatar khuezy commented on July 28, 2024

I've been experimenting w/ latency issues and hacked my way around fixing the latency by moving the server-adapter to origin-request edge lambda to the same distribution. Adding option for user to set edge mode in NextjsSite will kill 2 birds w/ 1 stone: fast latency going from middleware to server (both using L@E) and gives the server handler access to the geo data.

from open-next.

fwang avatar fwang commented on July 28, 2024

@khuezy just to clarify, r u accessing the geo data via CloudFront-* headers? Or are they available in NextRequest's geo field (ie. request.geo.city)?

from open-next.

khuezy avatar khuezy commented on July 28, 2024

@fwang I seen them in the CloudFront-* headers. Vercel has some logic to package that nicely into the request.geo, which open-next might want to do.

from open-next.

Makisuo avatar Makisuo commented on July 28, 2024

Just stumbled on this and it seems like this isn't working anymore. Using SST 3.0.11 geo headers are always empty for me in my next middleware

from open-next.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.