aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
461 stars 116 forks source link

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

Open mathvbarone opened 3 years ago

mathvbarone commented 3 years ago

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

tchenu commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

dowrow commented 1 year ago

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

vizardkill commented 1 year ago

up

gijsbotje commented 1 year ago

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 commented 3 months ago

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/