sladg / nextjs-lambda

Lambda deployments for Nextjs12 & Nextjs13 (standalone). Easy CLI commands to get your standalone Next output to run in AWS Lambda (not @Edge)! Uses CDK in behind and produces code zips importable to Terraform, Serverless, Azure, etc.
MIT License
173 stars 19 forks source link

Forward the Host header to the origin #82

Open DmitriyKabanov opened 1 year ago

DmitriyKabanov commented 1 year ago

On the application layer we need to access the Host header in the request object, however it's not equal to any of alternative domain names.

As of now, header behaviour is hardcoded as CacheHeaderBehavior.allowList('accept', 'accept-language', 'content-language', 'content-type', 'user-agent', 'authorization').

Adding host to this list breaks the API Gateway with 403 error, unless API Gateway is configured with custom domain names.

sladg commented 1 year ago

Yeah, ApiGw expects Host to be Cloudfront. We would need to do mapping of original Host to something like X-Host. I would need to take a look what is recommended way of doing this in AWS.

DmitriyKabanov commented 1 year ago

Any ETA on this?

sladg commented 1 year ago

@DmitriyKabanov I did a research and to support this properly, we would need to create Edge Lambda that would handle renaming headers and forwarding them. It's quite unfortunate as I'm very much trying to stay away from Edge lambda due to limitations and deployment speed. I'm experimenting with keeping Edge lambdas same after first deploy.

No ETA yet, definitely bigger task than expected.

Any chance you could provide me with your usecase? Aka. what are you using Host for? Maybe I can suggest workaround in the meantime.

DmitriyKabanov commented 1 year ago

The use case is to build a redirectUrl to get back to the service.

sladg commented 1 year ago

That sounds like something that can be done by many different ways. For example:

DmitriyKabanov commented 1 year ago

For sure, it could be done by many different ways. I'm not opposed to put a temporary workaround (as we already did). I'm curious when this enchantment would be addressed?