amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

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

Open mathvbarone opened this issue 3 years ago • 7 comments

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 avatar Oct 26 '21 08:10 mathvbarone

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:

tchenu avatar Mar 01 '22 17:03 tchenu

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 avatar Jun 22 '22 15:06 CauanCabral

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

CauanCabral avatar Sep 06 '22 19:09 CauanCabral

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

dowrow avatar Dec 28 '22 19:12 dowrow

up

vizardkill avatar Feb 22 '23 14:02 vizardkill

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/<*>.

gijsbotje avatar Mar 08 '23 10:03 gijsbotje