Are you guys going to add support for Gatsby at an...
# sst
r
Are you guys going to add support for Gatsby at any point? I'm currently using the static site stack for it at the moment.
f
Hey @Roger Rajaratnam, is there any specific feature you are looking for with a Gatsby specific construct?
r
Hey, there are a couple of things: • Ability to create cloudfront/lambda@edge functions to handle url rewrite rules • Support for all rendering methods such server side rendering, and deferred static site generation
The current static site construct, doesn't really work that well as cloudfront can't handle loading the default document object (index.html) for sub directories, so support for that via an option on the construct would be awesome
I've created a cloundfront function and added it manually to the cloudfront distribution manually to do this for the time being and I'm looking at adding a lambda@edge function to do that right now
f
I will keep you posted when we get to this, and I will probably reach out to clarify on some of the details 🙂
Oh btw, as a side note, have u run into a similar user as @Devin in this GH issue https://github.com/serverless-stack/serverless-stack/issues/1332? According to Gastby:
Copy code
In order for all the features of your site to work correctly, you must instead use your S3 bucket's Static Website Hosting Endpoint as the CloudFront origin
But if you are using the
StaticSite
construct, the CloudFront distribution is using the
S3 Bucket as Origin
. Instead of what Gastby suggests which is enabling the static hosting option on the S3 bucket and using the static hosting URL as an
HTTP Origin
.
Let me know if that makes sense to u, and if you have run into this issue.
d
If my understanding of what Roger is saying is correct, we're essentially both experiencing the same issue.
r
Enabling the static hosting option on the S3 bucket is not ideal as it makes the S3 bucket public and files can be accessed accessed via the s3 bucker url.
What I have done to make this work currently is to create a CloudFront Function with the following code
Copy code
function handler(event) {
    var request = event.request;
    var uri = request.uri;
    
    // Check whether the URI is missing a file name.
    if (uri.endsWith('/')) {
        request.uri += 'index.html';
    } 
    // Check whether the URI is missing a file extension.
    else if (!uri.includes('.')) {
        request.uri += '/index.html';
    }

    return request;
}
I have assigned this to the CloudFront distribution as a Viewer request function
The root cause of the issue is CloudFronts decision to only serve the default root object for the root folder: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DefaultRootObject.html
I have realised that I can implement this redirect using lambda@edge on the StaticSite construct (https://docs.serverless-stack.com/constructs/StaticSite#using-lambdaedge) so will do that for the time being.
d
Roger if you successfully pull that off I’d love to see an example. I wasn’t able to get mine running
r
I'll post solution here when I do.
Let me know if you have any questions.
I've chosen to go with lambda@edge, but have included an example for cloud front functions as well.
d
@Roger Rajaratnam where did you get the value for the certificate. I can copy the
arn
from the s3 bucket in the console. But yours has an ID. Is that because your cert is from an external, non route53 cert?
r
@Devin I got the ARN from ACM (AWS Certificate Manager)
Copy code
AWS Certificate Manager > Certificates > domain
My domain is registered with Gandi.net, so it is external, if you have your domain registered via Route52, then you can just use
Copy code
domainName: "<http://domain.com|domain.com>",
domainAlias: "<http://www.domain.com|www.domain.com>",
d
Thanks. I followed your example but then cloudfront blocked my domain. I prob did something goofy
r
I'm happy to have a look at your config, if you are able to share it.
I requested a certificate for my domain in ACM, then did the validation, an it just worked.
d
Thanks. Let me start by trying with the domain alias and all. See where that gets me