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

NextJS i18n cannot redirect based on domain, Amplify should forward "X-Forwarded-Host" header #2340

Open
mathvbarone opened this issue Oct 26, 2021 · 7 comments
Labels
feature-request New feature or request

Comments

@mathvbarone
Copy link

mathvbarone commented Oct 26, 2021

Is your feature request related to a problem? Please describe.
We would like to have our website using i18n feature from NextJS based on Domain Routing.

The way Amplify was designed, it creates an internal Cloudfront to manage DNS and certificates, and forward the request to another Cloudfront attached to the branch.

The problem is that, by adding a rewrite rule, no information is propagated about the Host and then NextJS can not redirect the request based on the domain. Check the diagram bellow:

image

If I intercept the request between internal CloudFront and the one rewritten to Serverless these are the only headers propagated:

{
  "user-agent": "Amazon CloudFront",
  "x-amz-cf-id": "...",
  "cookie": "...",
  "x-forwarded-for": "...",
  "via": "...",
  "accept-encoding": "gzip",
  "pragma": "no-cache",
  "sec-ch-ua": "\"Chromium\";v=\"94\", \"Google Chrome\";v=\"94\", \";Not A Brand\";v=\"99\"",
  "sec-ch-ua-mobile": "?0",
  "sec-ch-ua-platform": "\"Linux\"",
  "upgrade-insecure-requests": "1",
  "sec-fetch-site": "none",
  "sec-fetch-mode": "navigate",
  "sec-fetch-user": "?1",
  "sec-fetch-dest": "document",
  "cloudfront-viewer-country": "DE",
  "cache-control": "no-cache",
  "x-amplify-isreverseproxy": "true"
}

As you can see, no Host information, and since it is working as a reverse proxy, x-forwarded-host should be added in order to make it consistent and possible to integrate it better into the other layers.

Describe the solution you'd like
Internal Cloudfront created by Amplify to manage DNS and Certificates should forward x-forwarded-host header, so nextjs can forward the request to the correct domain according to the request origin.

image

@mathvbarone mathvbarone added the feature-request New feature or request label Oct 26, 2021
@tchenu
Copy link

tchenu commented Mar 1, 2022

I've literally been on this issue for 3 days, it's the worst possible service to deploy a Next (SSR) application, honestly. I have to do X applications per domain and run with an environment variable to indicate the current domain. :introducing-facepalm-here:

@CauanCabral
Copy link

Hi folks, any news about domain routing with Amplify?

Theres some way we can work around it by ourselves in the meantime (without having to work with multiple branches or applications of the same code)?

Issue #2345 has the same problem.

@CauanCabral
Copy link

We will celebrate 1 year with that and the #2345 issues without ANY solution, explanation, or workaround, that's sad.

@dowrow
Copy link

dowrow commented Dec 28, 2022

You are announcing Next13 support now. This is an old unsolved bug, not a feature request.

@vizardkill
Copy link

up

@gijsbotje
Copy link

We ran into the same issue where it just redirects to the default domain. They clearly state that it should be supported, but it doesn't seem to work out of the box with no further documentation.

We are now forced to deploy each language as a separate app and use rewrites to go from site.fr to site.fr/fr-fr/. Besides that we now need to use 13 rewrites to exclude the _next/ routes and other static files before rewriting everything from /<*> to /fr-fr/<*>.

@mauerbac
Copy link
Member

Hello -- Any chance you could see if this is now working? We just made improvements to forward more headers which should help here

https://aws.amazon.com/blogs/mobile/cdn-caching-improvements-for-better-app-performance-with-aws-amplify-hosting/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants