tonyfromundefined / nuxt-serverless

Nuxt.js Serverless SSR Starter on AWS (Lambda + API Gateway + S3) with Serverless Framework
254 stars 32 forks source link

CloudFront? #11

Closed larswww closed 4 years ago

larswww commented 4 years ago

Hi Tony!

Thank you for making this template. It's exactly what I was looking for :)

When you say "use your own domain", how would you configure that? I presume it means also needing a cloudfront distrubtion, forwarding certain paths to S3, and some to the API Gateway origin?

And I take it the S3 is to store anything static, which is then served via express/nuxt?

Thanks again

larswww commented 4 years ago

For anyone else looking to solve this!

The only real quirk is that you have to set the default root object of your CloudFront distribution to / - otherwise it'll keep on redirecting directly to the generated API url, not your domain. In a spa you would set that default object to be index.html.

Domain/cloudfront distribution setup steps if anyone else was wondering;

  1. Setup a domain in Route 53
  2. Get SSL certificate in Certificate Manager for your domain
  3. Copy the invoke URL of your deployed nuxt app from API Gateway
  4. Create a CloudFront distribution
  5. Add the API Gateway endpoint url you just copied as an origin
  6. Add the SSL cert and yourdomain as alternate CNAME
  7. Set CloudFronts (default/*) behavior pointing to that origin
  8. PROFIT.

I did not use the internal API in the project and instead directed cloudfront to proxy mydomain.com/api to a separately deployed API Gateway api.

Thanks again Tony this helped me out