serverless-nextjs / serverless-next.js

⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
MIT License
4.47k stars 456 forks source link

`originUrl.includes("s3")` produces false positives #761

Open danielberndt opened 4 years ago

danielberndt commented 4 years ago

Describe the bug

Hi there! 👋

I'm adding an origin of this form http://foo.s3-website-eu-west-1.amazonaws.com.

As other issues revealed those kind of origins are not an S3OriginConfig but a CustomOriginConfig.

So it might help to exclude these kind of origins, or maybe allow setting an extra flag to to mark an origin as non-S3OriginConfig.

here's the problematic line of code: https://github.com/serverless-nextjs/serverless-next.js/blob/e7b5c1d302eef1daf32d150e0f12f94d4311eb0a/packages/serverless-components/aws-cloudfront/lib/getOriginConfig.js#L18

danielcondemarin commented 4 years ago

Probably the simplest would be to check if is an S3 website url, e.g. ends with either of s3-website-Region.amazonaws.com or s3-website.Region.amazonaws.com and use a custom origin in that case.

s3-website dash (-) Region ‐ http://bucket-name.s3-website-Region.amazonaws.com s3-website dot (.) Region ‐ http://bucket-name.s3-website.Region.amazonaws.com

Happy to take a PR for that if you have the time 👍